[FFmpeg-devel] [PATCH 1/3] Replace DUP_DATA & memset with 0 by av_mallocz

Andrey Utkin andrey.krieger.utkin at gmail.com
Mon Sep 17 19:12:56 CEST 2012

2012/9/17 Nicolas George <nicolas.george at normalesup.org>:
> Le jour du Génie, an CCXX, Andrey Utkin a écrit :
>> Offtop childish question: does malloc(struct_size * number) always alloc
>> same size as calloc(number, struct_size)? I.e. is having two params in
>> calloc() a nonsense?
> No: struct_size * number can overflow and allocate less memory than
> intended. calloc with its two arguments checks the overflow and returns an
> error.

Thanks. I though it has something to do with aligning of individual
array entries.
Your note made me check my line
pkt->side_data = av_mallocz(pkt->side_data_elems * sizeof(*pkt->side_data));
There i didn't check for multiplication overflow, but as the same
memory quantity was successfully allocated for original packet, it
should be safe to request same size, isn't it?
Andrey Utkin

More information about the ffmpeg-devel mailing list