This is the mail archive of the
mailing list for the glibc project.
Re: [PATCH] Use calloc (x, y) instead malloc (x * y).
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: Andreas Jaeger <aj at suse dot com>
- Cc: OndÅej BÃlka <neleai at seznam dot cz>, <libc-alpha at sourceware dot org>
- Date: Fri, 25 Oct 2013 15:38:32 +0000
- Subject: Re: [PATCH] Use calloc (x, y) instead malloc (x * y).
- Authentication-results: sourceware.org; auth=none
- References: <20131025084008 dot GA17443 at domone> <526A319B dot 80909 at suse dot com>
On Fri, 25 Oct 2013, Andreas Jaeger wrote:
> What about adding a wrapper around malloc instead?
Note that, for efficiency, in such an (inline / macro) wrapper you want to
distinguish the argument counting the number of elements (not constant)
and the argument counting the size of an element (almost always constant,
so SIZE_MAX / size gets folded to a constant) - and make sure each call
passes the arguments in the right order, which may not always be the order
the existing multiplication is written in.
In cases where the size is obviously constant, e.g. "2 * sizeof (struct
__gconv_step)", there is no need for any change (although wrappers should
also get completely optimized away in such cases).
The diff hunk that does
looks suspicious to me, as does the removal of "}" at the end of
localedata/collate-test.c and nscd/initgrcache.c.
Joseph S. Myers