| 1 |
extern void free (void *); |
| 2 |
char *xstrdup (const char *) |
| 3 |
__attribute__((malloc (free), returns_nonnull)); |
| 4 |
|
| 5 |
void test_1 (const char *s) |
| 6 |
{ |
| 7 |
char *p = xstrdup (s); |
| 8 |
free (p); |
| 9 |
} |
| 10 |
|
| 11 |
/* Verify that we don't issue -Wanalyzer-possible-null-dereference |
| 12 |
when the allocator has __attribute__((returns_nonnull)). */ |
| 13 |
|
| 14 |
char *test_2 (const char *s) |
| 15 |
{ |
| 16 |
char *p = xstrdup (s); |
| 17 |
p[0] = 'a'; /* { dg-bogus "possibly-NULL" } */ |
| 18 |
return p; |
| 19 |
} |
| 20 |
|
| 21 |
void test_3 (const char *s) |
| 22 |
{ |
| 23 |
char *p = xstrdup (s); /* { dg-message "allocated here" } */ |
| 24 |
} /* { dg-warning "leak of 'p'" } */ |