Why was the reallocarray function not added to glibc?

Dennis Wölfing denniswoelfing@gmx.de
Sat Apr 8 19:41:00 GMT 2017


On 07.04.2017 22: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

It seems that the INT_MULTIPLY_OVERFLOW implementation uses compiler
builtins only with GCC 7 or higher because it uses
__builtin_mul_overflow_p. However for the implementation of reallocarray
it would be sufficient (or even preferable) to use__builtin_mul_overflow
which was introduced with GCC 5. So I guess it's better to simply use
__builtin_mul_overflow when __GNUC__ >= 5, and use the current
implementation otherwise.



More information about the Libc-alpha mailing list