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. 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 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 argument in call to memory copy function}} 17 // expected-note@-1{{Null pointer argument in call to memory copy function}} 18 } 19 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 argument in call to memory copy function}} 23 // expected-note@-1{{Null pointer argument in call to memory copy function}} 24 } 25 26 void f3(char *source) { 27 char *destination = 0; // FIXME: There should be a note here as well. 28 destination = destination + 0; // expected-note{{Null pointer value stored to 'destination'}} 29 memcpy(destination, source, 10); // expected-warning{{Null pointer argument in call to memory copy function}} 30 // expected-note@-1{{Null pointer argument in call to memory copy function}} 31 } 32 33 void f4(char *source) { 34 char *destination = 0; // FIXME: There should be a note here as well. 35 destination = destination - 0; // expected-note{{Null pointer value stored to 'destination'}} 36 memcpy(destination, source, 10); // expected-warning{{Null pointer argument in call to memory copy function}} 37 // expected-note@-1{{Null pointer argument in call to memory copy function}} 38 } 39 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 argument in call to memory copy function}} 44 // expected-note@-1{{Null pointer argument in call to memory copy function}} 45 } 46 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 argument in call to memory copy function}} 51 // expected-note@-1{{Null pointer argument in call to memory copy function}} 52 } 53