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: [PATCH v3] Add reallocarray function.


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


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