[Bug middle-end/80346] pessimistic stringop-overflow

bonzini at gnu dot org gcc-bugzilla@gcc.gnu.org
Fri Apr 7 17:28:00 GMT 2017


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

Paolo Bonzini <bonzini at gnu dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bonzini at gnu dot org

--- Comment #4 from Paolo Bonzini <bonzini at gnu dot org> ---
The beautified code should be something like this:

#include <stddef.h>

void *g_malloc0(size_t n) __attribute__((__alloc_size__(1)));
void *g_malloc0_n(size_t n, size_t s) __attribute__((__alloc_size__(1, 2)));

unsigned *f (int length)
{
  int tables_nr = (length - 24) / sizeof(unsigned);
  if (tables_nr <= 0)
    return NULL;
  return (unsigned *) (__extension__ ({
        size_t n = tables_nr;
        size_t s = sizeof (unsigned);
        void *p;
        if (s == 1)
          p = g_malloc0 (n);
        else if (__builtin_constant_p (n)
                 && (s == 0 || n <= ((size_t)-1) / s))
          p = g_malloc0 (n * s);
        else
          p = g_malloc0_n (n, s);
        p;
  }));
}

> __s is non-zero, and __n is equal to SIZE_MAX

n is not constant at the g_malloc0_n call site, so I'm not sure what deduction
can be made.


More information about the Gcc-bugs mailing list