Artem Dergachev | 95f9a68 | 2018-03-30 19:27:42 +0000 | [diff] [blame] | 1 | // RUN: %clang_analyze_cc1 -w -x c -analyzer-checker=core,unix -analyzer-output=text -verify %s |
Artem Dergachev | 2064e82 | 2017-09-27 09:33:37 +0000 | [diff] [blame] | 2 | |
| 3 | // Avoid the crash when finding the expression for tracking the origins |
Artem Dergachev | d85a994 | 2017-09-27 10:59:06 +0000 | [diff] [blame] | 4 | // of the null pointer for path notes. |
Artem Dergachev | 2064e82 | 2017-09-27 09:33:37 +0000 | [diff] [blame] | 5 | void pr34373() { |
Artem Dergachev | 8c80061 | 2017-09-27 09:50:45 +0000 | [diff] [blame] | 6 | int *a = 0; // expected-note{{'a' initialized to a null pointer value}} |
Artem Dergachev | 2064e82 | 2017-09-27 09:33:37 +0000 | [diff] [blame] | 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 | } |
Artem Dergachev | 95f9a68 | 2018-03-30 19:27:42 +0000 | [diff] [blame] | 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) { |
George Karpenkov | 70ec1dd | 2018-06-26 21:12:08 +0000 | [diff] [blame^] | 27 | char *destination = 0; // expected-note{{'destination' initialized to a null pointer value}} |
Artem Dergachev | 95f9a68 | 2018-03-30 19:27:42 +0000 | [diff] [blame] | 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) { |
George Karpenkov | 70ec1dd | 2018-06-26 21:12:08 +0000 | [diff] [blame^] | 34 | char *destination = 0; // expected-note{{'destination' initialized to a null pointer value}} |
Artem Dergachev | 95f9a68 | 2018-03-30 19:27:42 +0000 | [diff] [blame] | 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 | } |