[FFmpeg-devel] [PATCH] [RFC] libavutil/mem.c: Check return value of posix_memalign

Reimar Döffinger Reimar.Doeffinger
Fri Feb 13 16:37:06 CET 2009


On Fri, Feb 13, 2009 at 04:08:23PM +0100, Patrik Kullman wrote:
> In my hunt to fix compilation warnings for ffmpeg, learn ffmpeg
> internals and learn C, I've come up with the patch to get rid of the
> "warn_unused_result" warning for mem.c
> 
> Possibly horribly wrong ;)

> Index: libavutil/mem.c
> ===================================================================
> --- libavutil/mem.c	(revision 17209)
> +++ libavutil/mem.c	(working copy)
> @@ -63,7 +63,12 @@
>      ptr = (char*)ptr + diff;
>      ((char*)ptr)[-1]= diff;
>  #elif HAVE_POSIX_MEMALIGN
> -    posix_memalign(&ptr,16,size);
> +    if (posix_memalign(&ptr,16,size) != 0)
> +#if HAVE_MEMALIGN
> +        ptr = memalign(16,size);
> +#else
> +        ptr = malloc(size);
> +#endif
>  #elif HAVE_MEMALIGN
>      ptr = memalign(16,size);
>      /* Why 64?

IMO make that
if (posix_memalign(&ptr,16,size) != 0)
    ptr = NULL;
even though ptr is initialized to NULL already and I'd certainly expect
that no posix_memalign implementation would break this, it seems like a
somewhat sensible approach.




More information about the ffmpeg-devel mailing list