[PATCH v3] Add reallocarray function.

Florian Weimer fweimer@redhat.com
Mon May 8 07:34:00 GMT 2017


On 04/21/2017 02:16 PM, Dennis Wölfing wrote:
> +static void
> +merror (const char *msg)
> +{
> +  ++errors;
> +  printf ("Error: %s.\n", msg);
> +}

I don't think this provides additional useful information compared to 
TEST_VERIFY, so you could simply use that.  It's also not necessary to 
free pointers on test failure paths (for allocations which succeeded, 
but should not have), so you can simplify the test a bit further.

Further comments:

In check_mul_overflow, you can use a local variable instead of the 
preprocessor macro HALF_INTERNAL_SIZE_T.

An interposed malloc will not use INTERNAL_SIZE_T and will not interpose 
reallocarray, so reallocarray will fail allocations when it does not 
have to.  I think you need too check_mul_overflow variants, one for use 
in calloc (with INTERNAL_SIZE_T), and one for use in reallocarray.  It's 
probably best to leave calloc alone in this patch and only add a 
size_t-based check_mul_overflow in this patch.

You should add

libc_hidden_proto (__libc_reallocarray)

to include/stdlib.h, matched by

libc_hidden_def (__libc_reallocarray)

in malloc/reallocarray.c.  This way, libc-internal calls to reallocarray 
will not go through the PLT.

I'm not sure if the alias machinery in malloc/reallocarray.c is correct. 
  I think you only need a weak_alias for reallocarray.  (It has to be 
weak to support static linking of glibc-internal calls to 
__libc_reallocarray, without conflicting with a user-supplied 
reallocarray function.)

Otherwise, the patch looks good.

Thanks,
Florian



More information about the Libc-alpha mailing list