[PATCH v4] Add reallocarray function.
DJ Delorie
dj@redhat.com
Thu May 11 17:28:00 GMT 2017
Dennis Wlfing <denniswoelfing@gmx.de> writes:
>>> diff --git a/malloc/reallocarray.c b/malloc/reallocarray.c
>>> +void *
>>> +__libc_reallocarray (void *optr, size_t nmemb, size_t elem_size)
>
> The header include/stdlib.h (not to be confused with stdlib/stdlib.h) is
> an internal glibc header. It declares the function prefixed with __libc_
> so that other glibc functions can call it without causing namespace
> problems. In the public headers only reallocarray is declared which is a
> weak alias for __libc_reallocarray.
I was mostly concerned with the __THROW differences. I've seen those
cause problems in the past.
> The check_mul_overflow_size_t function was put in the new
> malloc-private.h header because malloc-internal.h is also used in other
> parts of glibc.
I have no problems with other parts of glibc seeing it, as long as it
has a suitable name. I'm just trying to avoid having too many headers
without a good reason for them.
>>> + /* Overflow should leave buffer untouched. */
>>
>> This requirement isn't documented anywhere...
>
> The reallocarray documentation says that reallocarray is equivalent to
> realloc(ptr, nmemb*size) and the realloc documentation says it does not
> modify the memory block on failure.
True, but overflow is a new condition that realloc doesn't have, that's
all, and since overflow checking is the *reason* for reallocarray, it
makes sense to clarify how it works.
More information about the Libc-alpha
mailing list