| 1 |
/* PR middle-end/104069 - -Werror=use-after-free false positive on |
| 2 |
elfutils-0.186 |
| 3 |
{ dg-do compile } |
| 4 |
{ dg-options "-Wall" } */ |
| 5 |
|
| 6 |
typedef __SIZE_TYPE__ size_t; |
| 7 |
|
| 8 |
extern void* realloc (void *, size_t); |
| 9 |
|
| 10 |
void* __libdw_unzstd (size_t todo) |
| 11 |
{ |
| 12 |
void *sb = 0; |
| 13 |
|
| 14 |
for ( ; ; ) |
| 15 |
{ |
| 16 |
// Ran only once. |
| 17 |
if (!sb) |
| 18 |
{ |
| 19 |
char *b = realloc (sb, todo); |
| 20 |
if (!b) |
| 21 |
break; |
| 22 |
|
| 23 |
sb = b; |
| 24 |
} |
| 25 |
|
| 26 |
todo -= 1; |
| 27 |
if (todo == 0) |
| 28 |
break; |
| 29 |
} |
| 30 |
|
| 31 |
// Shrink buffer: leave only one byte for simplicity. |
| 32 |
char *b = realloc (sb, 1); |
| 33 |
if (b) |
| 34 |
sb = b; |
| 35 |
else |
| 36 |
{ |
| 37 |
// Realloc failed mysteriously, leave 'sb' untouched. |
| 38 |
} |
| 39 |
|
| 40 |
return sb; // { dg-bogus "-Wuse-after-free" } |
| 41 |
} |