[Bug middle-end/104069] -Werror=use-after-free false positive on elfutils-0.186

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Jan 19 20:24:53 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104069

--- Comment #14 from Martin Sebor <msebor at gcc dot gnu.org> ---
Removing the test for !size from the first conditional avoids the warning.  I
don't fully understand what the code tries to do but the following avoids it at
-O2 (only):

void *xrealloc (void *ptr, int size)
{
  if (!size)
    size = 1;
  void *ret = __builtin_realloc (ptr, size);
  if (!ret)
    ret = __builtin_realloc (ptr, 1);
  if (!ret) {
    ret = __builtin_realloc (ptr, size);
    if (!ret)
      ret = __builtin_realloc(ptr, 1);
    if (!ret)
      __builtin_abort ();
  }
  return ret;
}


More information about the Gcc-bugs mailing list