2010-02-05 10:06:54 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify %s
|
|
|
|
// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify %s
|
2009-04-28 21:52:13 +08:00
|
|
|
|
2009-04-29 13:59:48 +08:00
|
|
|
// Test if the 'storage' region gets properly initialized after it is cast to
|
|
|
|
// 'struct sockaddr *'.
|
|
|
|
|
2009-08-20 12:48:23 +08:00
|
|
|
typedef unsigned char __uint8_t;
|
|
|
|
typedef unsigned int __uint32_t;
|
|
|
|
typedef __uint32_t __darwin_socklen_t;
|
|
|
|
typedef __uint8_t sa_family_t;
|
|
|
|
typedef __darwin_socklen_t socklen_t;
|
|
|
|
struct sockaddr { sa_family_t sa_family; };
|
|
|
|
struct sockaddr_storage {};
|
2009-07-11 04:10:06 +08:00
|
|
|
|
2010-01-10 04:43:19 +08:00
|
|
|
void getsockname();
|
|
|
|
|
2009-04-28 21:52:13 +08:00
|
|
|
void f(int sock) {
|
|
|
|
struct sockaddr_storage storage;
|
|
|
|
struct sockaddr* sockaddr = (struct sockaddr*)&storage;
|
|
|
|
socklen_t addrlen = sizeof(storage);
|
|
|
|
getsockname(sock, sockaddr, &addrlen);
|
|
|
|
switch (sockaddr->sa_family) { // no-warning
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
2009-06-18 14:29:10 +08:00
|
|
|
|
|
|
|
struct s {
|
|
|
|
struct s *value;
|
|
|
|
};
|
|
|
|
|
2009-07-22 02:45:53 +08:00
|
|
|
void f1(struct s **pval) {
|
2009-06-18 14:29:10 +08:00
|
|
|
int *tbool = ((void*)0);
|
|
|
|
struct s *t = *pval;
|
|
|
|
pval = &(t->value);
|
2009-10-14 14:05:09 +08:00
|
|
|
tbool = (int *)pval; // use the cast-to type 'int *' to create element region.
|
2009-06-18 14:49:35 +08:00
|
|
|
char c = (unsigned char) *tbool; // Should use cast-to type to create symbol.
|
2009-10-14 14:05:09 +08:00
|
|
|
if (*tbool == -1) // here load the element region with the correct type 'int'
|
2009-07-31 06:37:41 +08:00
|
|
|
(void)3;
|
2009-06-18 14:29:10 +08:00
|
|
|
}
|
|
|
|
|
2009-06-19 12:51:14 +08:00
|
|
|
void f2(const char *str) {
|
|
|
|
unsigned char ch, cl, *p;
|
|
|
|
|
|
|
|
p = (unsigned char *)str;
|
|
|
|
ch = *p++; // use cast-to type 'unsigned char' to create element region.
|
|
|
|
cl = *p++;
|
|
|
|
if(!cl)
|
|
|
|
cl = 'a';
|
|
|
|
}
|
2010-01-05 19:49:21 +08:00
|
|
|
|
|
|
|
// Test cast VariableSizeArray to pointer does not crash.
|
|
|
|
void *memcpy(void *, void const *, unsigned long);
|
|
|
|
typedef unsigned char Byte;
|
|
|
|
void doit(char *data, int len) {
|
|
|
|
if (len) {
|
|
|
|
Byte buf[len];
|
|
|
|
memcpy(buf, data, len);
|
|
|
|
}
|
|
|
|
}
|
2010-01-14 11:45:06 +08:00
|
|
|
|
2010-01-15 03:47:50 +08:00
|
|
|
// PR 6013 and 6035 - Test that a cast of a pointer to long and then to int does not crash SValuator.
|
|
|
|
void pr6013_6035_test(void *p) {
|
|
|
|
unsigned int foo;
|
|
|
|
foo = ((long)(p));
|
|
|
|
(void) foo;
|
2010-01-14 11:45:06 +08:00
|
|
|
}
|