Luca Barbato <lu_z...@gentoo.org> writes: > On 07/09/2012 02:28 PM, Luca Barbato wrote: >> On 07/09/2012 12:18 PM, Måns Rullgård wrote: >>> Tomas Härdin <tomas.har...@codemill.se> writes: >>> >>>> On Sun, 2012-07-08 at 21:12 +0100, Måns Rullgård wrote: >>>>> Tomas Härdin <tomas.har...@codemill.se> writes: >>>>>> +void *av_calloc(size_t nmemb, size_t size) >>>>>> +{ >>>>>> + if (size <= 0 || nmemb >= INT_MAX / size) >>>>>> + return NULL; >>>>>> + return av_mallocz(nmemb * size); >>>>>> +} >>>>> >>>>> The places where this would be used don't in general need zeroed memory. >>>> >>>> Indeed, but calloc() zeroes memory so I'd say it's expected behavior. >>> >>> That's a ridiculous argument. Give the function another name. >>> >> >> What about something along the lines of >> >> #define av_malloc_array(nmemb, size) \ >> av_malloc((size <= 0 || nmemb >= INT_MAX / size) ? 0 : nmemb * size); >> >> lu >> > > diff --git a/libavutil/mem.h b/libavutil/mem.h > index cd8490b..15b804d 100644 > --- a/libavutil/mem.h > +++ b/libavutil/mem.h > @@ -79,6 +79,19 @@ > void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1); > > /** > + * Helper macro to allocate a block of size * nmemb bytes with > + * using av_malloc() > + * @param nmemb Number of elements > + * @param size Size of the single element > + * @return Pointer to the allocated block, NULL if the block cannot > + * be allocated. > + * @see av_malloc() > + */ > + > +#define av_malloc_array(nmemb, size) \ > + av_malloc((size <= 0 || nmemb >= INT_MAX / size) ? 0 : nmemb * size);
Please make this a function (inline or otherwise) to avoid any problems with multiple evaluation of arguments. -- Måns Rullgård m...@mansr.com _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel