blob: c73f64066b28610677e8305812449d9b689ea365 [file] [log] [blame]
Artem Dergachev95f9a682018-03-30 19:27:42 +00001// RUN: %clang_analyze_cc1 -w -x c -analyzer-checker=core,unix -analyzer-output=text -verify %s
Artem Dergachev2064e822017-09-27 09:33:37 +00002
3// Avoid the crash when finding the expression for tracking the origins
Artem Dergachevd85a9942017-09-27 10:59:06 +00004// of the null pointer for path notes.
Artem Dergachev2064e822017-09-27 09:33:37 +00005void pr34373() {
Artem Dergachev8c800612017-09-27 09:50:45 +00006 int *a = 0; // expected-note{{'a' initialized to a null pointer value}}
Artem Dergachev2064e822017-09-27 09:33:37 +00007 (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 Dergachev95f9a682018-03-30 19:27:42 +000010
11typedef __typeof(sizeof(int)) size_t;
12void *memcpy(void *dest, const void *src, unsigned long count);
13
14void 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
20void 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
26void f3(char *source) {
George Karpenkov70ec1dd2018-06-26 21:12:08 +000027 char *destination = 0; // expected-note{{'destination' initialized to a null pointer value}}
Artem Dergachev95f9a682018-03-30 19:27:42 +000028 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
33void f4(char *source) {
George Karpenkov70ec1dd2018-06-26 21:12:08 +000034 char *destination = 0; // expected-note{{'destination' initialized to a null pointer value}}
Artem Dergachev95f9a682018-03-30 19:27:42 +000035 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
40void 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
47void 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}