analyzer: Fix PR analyzer/101980
[official-gcc.git] / gcc / testsuite / gcc.dg / analyzer / malloc-2.c
blobbb93c53d3e0f155be989ed25cfa61d781eb0687a
1 /* Tests for precision-of-wording within malloc warnings. */
3 typedef __SIZE_TYPE__ size_t;
4 extern void *malloc(size_t);
5 extern void free(void *);
6 extern char *strcpy(char *__restrict __dest, const char *__restrict __src)
7 __attribute__((__nothrow__, __leaf__)) __attribute__((__nonnull__(1, 2)));
9 void test_1 (void)
11 void *p = malloc (1024); /* { dg-message "\\(1\\) this call could return NULL" } */
12 strcpy ((char *)p, "hello world"); /* { dg-warning "use of possibly-NULL 'p' where non-null expected" "warning" } */
13 /* { dg-message "\\(2\\) argument 1 \\('p'\\) from \\(1\\) could be NULL where non-null expected" "event" { target *-*-* } .-1 } */
14 free (p);
17 int *test_2 (void)
19 int *i = malloc (sizeof (int)); /* { dg-message "\\(1\\) this call could return NULL" } */
20 *i = 42; /* { dg-warning "dereference of possibly-NULL 'i'" "warning" } */
21 /* { dg-message "\\(2\\) 'i' could be NULL: unchecked value from \\(1\\)" "event" { target *-*-* } .-1 } */
22 return i;