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

Måns Rullgård mans
Fri Feb 13 16:47:23 CET 2009


Patrik Kullman <patrik at yes.nu> writes:

> On Fri, 2009-02-13 at 15:18 +0000, M?ns Rullg?rd wrote:
>> Patrik Kullman <patrik at yes.nu> writes:
>> 
>> > 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?
>> 
>> What is the warning?
>
> libavutil/mem.c: In function ?av_malloc?:
> libavutil/mem.c:66: warning: ignoring return value of ?posix_memalign?,
> declared with attribute warn_unused_result

That warning is bogus.  If posix_memalign() fails, memalign() will too
since they are likely to be the same function.  We set the pointer to
NULL before the call, so if it fails, we return NULL as we're supposed
to.

-- 
M?ns Rullg?rd
mans at mansr.com




More information about the ffmpeg-devel mailing list