[PATCH] Use calloc (x, y) instead malloc (x * y).

Andreas Jaeger aj@suse.com
Fri Oct 25 08:53:00 GMT 2013


On 10/25/2013 10:40 AM, Ondřej Bílka wrote:
> Hi,
> 
> As there were several bugs with possible overflows in malloc calculation
> we should try to prevent these. A simple heuristic is to use following
> cocinelle patch:
> 
> @@ expression e1, e2; @@
> 
> - malloc(e1 * e2)
> + calloc(e1, e2)
> 
> To handle easy case. OK to commit?

calloc returns 0-initialized memory, malloc does not - so, this could be
a pessimization.

What about adding a wrapper around malloc instead?

Andreas
-- 
 Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
  SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
   GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
    GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126



More information about the Libc-alpha mailing list