blob: f78ea69894890c9bfe0d0b52b4aa662573243d70 [file] [log] [blame]
Zhongxing Xu2fc32592009-04-29 01:50:12 +00001// RUN: clang-cc -analyze -checker-cfref -analyzer-store=region --verify %s
Zhongxing Xu2fc32592009-04-29 01:50:12 +00002
Zhongxing Xub1080ed2009-04-29 05:59:48 +00003// Test if the 'storage' region gets properly initialized after it is cast to
4// 'struct sockaddr *'.
5
Eli Friedmancb52d282009-07-10 20:10:06 +00006#include <sys/types.h>
Eli Friedman88bd3402009-07-10 22:27:56 +00007#include <sys/socket.h>
Eli Friedmancb52d282009-07-10 20:10:06 +00008
Zhongxing Xuc58e7852009-04-28 13:52:13 +00009void f(int sock) {
10 struct sockaddr_storage storage;
11 struct sockaddr* sockaddr = (struct sockaddr*)&storage;
12 socklen_t addrlen = sizeof(storage);
13 getsockname(sock, sockaddr, &addrlen);
14 switch (sockaddr->sa_family) { // no-warning
15 default:
16 ;
17 }
18}
Zhongxing Xu88c675f2009-06-18 06:29:10 +000019
20struct s {
21 struct s *value;
22};
23
Mike Stump95992262009-07-21 18:45:53 +000024void f1(struct s **pval) {
Zhongxing Xu88c675f2009-06-18 06:29:10 +000025 int *tbool = ((void*)0);
26 struct s *t = *pval;
27 pval = &(t->value);
Zhongxing Xu59c03ff2009-06-18 06:49:35 +000028 tbool = (int *)pval; // Should record the cast-to type here.
29 char c = (unsigned char) *tbool; // Should use cast-to type to create symbol.
Zhongxing Xu45257c32009-06-19 06:00:32 +000030 if (*tbool == -1)
Anders Carlsson9668b1f2009-07-30 22:37:41 +000031 (void)3;
Zhongxing Xu88c675f2009-06-18 06:29:10 +000032}
33
Zhongxing Xu005f07b2009-06-19 04:51:14 +000034void f2(const char *str) {
35 unsigned char ch, cl, *p;
36
37 p = (unsigned char *)str;
38 ch = *p++; // use cast-to type 'unsigned char' to create element region.
39 cl = *p++;
40 if(!cl)
41 cl = 'a';
42}