[FFmpeg-devel] [PATCH] avutil/internal: add FF_ALLOC_ARRAY_OR_GOTO & FF_ALLOCZ_ARRAY_OR_GOTO

Clément Bœsch u at pkh.me
Fri Apr 18 15:34:54 CEST 2014


On Fri, Apr 18, 2014 at 03:26:04PM +0200, Michael Niedermayer wrote:
> These are similar to the existing FF_ALLOCZ_OR_GOTO & FF_ALLOC_OR_GOTO
> 
> Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> ---
>  libavutil/internal.h |   18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/libavutil/internal.h b/libavutil/internal.h
> index 9c5546f..05a017f 100644
> --- a/libavutil/internal.h
> +++ b/libavutil/internal.h
> @@ -133,6 +133,24 @@
>      }\
>  }
>  
> +#define FF_ALLOC_ARRAY_OR_GOTO(ctx, p, size0, size1, label)\
> +{\

> +    p = av_malloc(size0, size1);\

??

> +    if (p == NULL) {\
> +        av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
> +        goto label;\
> +    }\
> +}
> +
> +#define FF_ALLOCZ_ARRAY_OR_GOTO(ctx, p, size0, size1, label)\
> +{\
> +    p = av_mallocz(size0, size1);\

ditto..

av_calloc maybe? Also in that case nmemb, n, or count for one of the size
would be more appropriate.

> +    if (p == NULL) {\
> +        av_log(ctx, AV_LOG_ERROR, "Cannot allocate memory.\n");\
> +        goto label;\
> +    }\
> +}
> +
>  #include "libm.h"

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140418/057a7744/attachment.asc>


More information about the ffmpeg-devel mailing list