This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v3] Add reallocarray function.
- From: Florian Weimer <fweimer at redhat dot com>
- To: Dennis Wölfing <denniswoelfing at gmx dot de>
- Cc: libc-alpha at sourceware dot org
- Date: Mon, 8 May 2017 09:34:50 +0200
- Subject: Re: [PATCH v3] Add reallocarray function.
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=fweimer at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D08D34E03F
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D08D34E03F
- References: <20170417140148.23212-1-denniswoelfing@gmx.de> <20170421121646.28392-1-denniswoelfing@gmx.de>
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