| 1 |
/* Tests for precision-of-wording within malloc warnings. */ |
| 2 |
|
| 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))); |
| 8 |
|
| 9 |
void test_1 (void) |
| 10 |
{ |
| 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); |
| 15 |
} |
| 16 |
|
| 17 |
int *test_2 (void) |
| 18 |
{ |
| 19 |
int *i = (int *) 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; |
| 23 |
} |