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] Use calloc (x, y) instead malloc (x * y).


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

-libnsl_hidden_def (nis_destroy_object)

looks suspicious to me, as does the removal of "}" at the end of 
localedata/collate-test.c and nscd/initgrcache.c.

-- 
Joseph S. Myers
joseph@codesourcery.com


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