[Bug middle-end/104069] -Werror=use-after-free false positive on elfutils-0.186
eike@sf-mail.de
gcc-bugzilla@gcc.gnu.org
Mon May 16 14:14:05 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104069
Rolf Eike Beer <eike@sf-mail.de> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |eike@sf-mail.de
--- Comment #23 from Rolf Eike Beer <eike@sf-mail.de> ---
Using gcc12 from 4943b75e9f06f0b64ed541430bb7fbccf55fc552.
$ cat rea.c
#include <stdlib.h>
char *
compact_buffer(char *inbuf, size_t oldlen, size_t k)
{
char *foo;
#ifdef WARN
char **buf = &foo;
#endif
foo = realloc(inbuf, k);
if (foo == NULL) {
#if defined(WARN) && defined(WARN2)
foo = inbuf;
return inbuf;
#else
return inbuf;
#endif
}
return foo;
}
$ gcc-12.0.1 -c -Wuse-after-free=3 -Irepos/Qsmtp/include rea.c
$ gcc-12.0.1 -c -DWARN -Wuse-after-free=2 -Irepos/Qsmtp/include rea.c
rea.c: In function 'compact_buffer':
rea.c:17:24: warning: pointer 'inbuf' may be used after 'realloc'
[-Wuse-after-free]
17 | return inbuf;
| ^~~~~
rea.c:11:15: note: call to 'realloc' here
11 | foo = realloc(inbuf, k);
| ^~~~~~~~~~~~~~~~~
$ gcc-12.0.1 -c -DWARN -DWARN2 -Wuse-after-free=2 -Irepos/Qsmtp/include rea.c
rea.c: In function 'compact_buffer':
rea.c:15:24: warning: pointer 'inbuf' may be used after 'realloc'
[-Wuse-after-free]
15 | return inbuf;
| ^~~~~
rea.c:11:15: note: call to 'realloc' here
11 | foo = realloc(inbuf, k);
| ^~~~~~~~~~~~~~~~~
rea.c:14:21: warning: pointer 'inbuf' may be used after 'realloc'
[-Wuse-after-free]
14 | foo = inbuf;
| ~~~~^~~~~~~
rea.c:11:15: note: call to 'realloc' here
11 | foo = realloc(inbuf, k);
| ^~~~~~~~~~~~~~~~~
More information about the Gcc-bugs
mailing list