This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Why was the reallocarray function not added to glibc?


On 07/04/17 21:47, Paul Eggert wrote:
> The patch should use gcc builtins (when available) to detect integer overflow instead of trying to do it by
> hand. You can do this by using the INT_MULTIPLY_OVERFLOW macro of Gnulib, documented here:
> 
> https://www.gnu.org/software/gnulib/manual/html_node/Integer-Type-Overflow.html
> 
> The easist way to use that macro is to copy gnulib intprops.h as-is into glibc, and then use "#include
> <intprops.h>". It need not be a public include file. Here's the current source:
> 
> http://git.savannah.gnu.org/cgit/gnulib.git/tree/lib/intprops.h

that is not just ugly but looks wrong too (it's
for signed mul).

the idiomatic unsigned mul overflow check is

  if (b && -1/b < a)
    return 0;
  c = a*b;

this can be recognized in the source by humans
and compilers too (fix the compiler if not) with
well defined semantics, i see no reason to use
non-portable built-ins or mountains of macros.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]