1 // RUN: %clang_analyze_cc1 -w -x c -analyzer-checker=core,unix -analyzer-output=text -verify %s
2 
3 // Avoid the crash when finding the expression for tracking the origins
4 // of the null pointer for path notes.
pr34373()5 void pr34373() {
6   int *a = 0; // expected-note{{'a' initialized to a null pointer value}}
7   (a + 0)[0]; // expected-warning{{Array access results in a null pointer dereference}}
8               // expected-note@-1{{Array access results in a null pointer dereference}}
9 }
10 
11 typedef __typeof(sizeof(int)) size_t;
12 void *memcpy(void *dest, const void *src, unsigned long count);
13 
f1(char * source)14 void f1(char *source) {
15   char *destination = 0; // expected-note{{'destination' initialized to a null pointer value}}
16   memcpy(destination + 0, source, 10); // expected-warning{{Null pointer passed as 1st argument to memory copy function}}
17                                        // expected-note@-1{{Null pointer passed as 1st argument to memory copy function}}
18 }
19 
f2(char * source)20 void f2(char *source) {
21   char *destination = 0; // expected-note{{'destination' initialized to a null pointer value}}
22   memcpy(destination - 0, source, 10); // expected-warning{{Null pointer passed as 1st argument to memory copy function}}
23                                        // expected-note@-1{{Null pointer passed as 1st argument to memory copy function}}
24 }
25 
f3(char * source)26 void f3(char *source) {
27   char *destination = 0; // expected-note{{'destination' initialized to a null pointer value}}
28   destination = destination + 0; // expected-note{{Null pointer value stored to 'destination'}}
29   memcpy(destination, source, 10); // expected-warning{{Null pointer passed as 1st argument to memory copy function}}
30                                    // expected-note@-1{{Null pointer passed as 1st argument to memory copy function}}
31 }
32 
f4(char * source)33 void f4(char *source) {
34   char *destination = 0; // expected-note{{'destination' initialized to a null pointer value}}
35   destination = destination - 0; // expected-note{{Null pointer value stored to 'destination'}}
36   memcpy(destination, source, 10); // expected-warning{{Null pointer passed as 1st argument to memory copy function}}
37                                    // expected-note@-1{{Null pointer passed as 1st argument to memory copy function}}
38 }
39 
f5(char * source)40 void f5(char *source) {
41   char *destination1 = 0; // expected-note{{'destination1' initialized to a null pointer value}}
42   char *destination2 = destination1 + 0; // expected-note{{'destination2' initialized to a null pointer value}}
43   memcpy(destination2, source, 10); // expected-warning{{Null pointer passed as 1st argument to memory copy function}}
44                                     // expected-note@-1{{Null pointer passed as 1st argument to memory copy function}}
45 }
46 
f6(char * source)47 void f6(char *source) {
48   char *destination1 = 0; // expected-note{{'destination1' initialized to a null pointer value}}
49   char *destination2 = destination1 - 0; // expected-note{{'destination2' initialized to a null pointer value}}
50   memcpy(destination2, source, 10); // expected-warning{{Null pointer passed as 1st argument to memory copy function}}
51                                     // expected-note@-1{{Null pointer passed as 1st argument to memory copy function}}
52 }
53