Bug#1006803: -Wuse-after-free: spurious warning
Package: gcc-12
Version: 12-20220302-1
Severity: normal
Dear GCC maintainers,
The following sample code gives a spurious warning with gcc-12:
gcc-12 -c -O3 -Wall test.c
test.c: In function ‘fun’:
test.c:5:25: warning: pointer ‘old’ used after ‘realloc’
[-Wuse-after-free]
5 | unsigned long s = new-old;
| ~~~^~~~
test.c:4:15: note: call to ‘realloc’ here
4 | void *new = realloc(old, n);
| ^~~~~~~~~~~~~~~
It should check that "old" is dereferenced.
Cheers,
--
Bill. <ballombe@debian.org>
Imagine a large red swirl here.
#include <stdlib.h>
unsigned long fun(void *old, void **ptr, size_t n)
{
void *new = realloc(old, n);
unsigned long s = new-old;
*ptr = new;
return s;
}
Reply to: