Commit a9493601 authored by Herve W's avatar Herve W Committed by Guillaume Poirier

* Allocating 16 bytes more for the MEMALIGN_HACK is enough. There's no

need for 1 more extra byte.

* Checking whether the to be allocated size is larger than INT_MAX,
doesn't assure that size+16 bytes for the MEMALIGN_HACK isn't larger
than INT_MAX.

* malloc might return NULL. Checking for it before using that pointer
seems like a good idea.
Patch by Herve W. H PPP O PPP W PPP aka PPP V+ffmpeg AH gmail PPP com
Original thread:
Date: Jun 29, 2006 1:21 PM
Subject: [Ffmpeg-devel] [PATCH] minor improvements to libavcodec/mem.c

Originally committed as revision 5559 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 3a6fc8fa
...@@ -50,11 +50,13 @@ void *av_malloc(unsigned int size) ...@@ -50,11 +50,13 @@ void *av_malloc(unsigned int size)
#endif #endif
/* let's disallow possible ambiguous cases */ /* let's disallow possible ambiguous cases */
if(size > INT_MAX) if(size > (INT_MAX-16) )
return NULL; return NULL;
#ifdef MEMALIGN_HACK #ifdef MEMALIGN_HACK
ptr = malloc(size+16+1); ptr = malloc(size+16);
if(!ptr)
return ptr;
diff= ((-(long)ptr - 1)&15) + 1; diff= ((-(long)ptr - 1)&15) + 1;
ptr += diff; ptr += diff;
((char*)ptr)[-1]= diff; ((char*)ptr)[-1]= diff;
...@@ -104,7 +106,7 @@ void *av_realloc(void *ptr, unsigned int size) ...@@ -104,7 +106,7 @@ void *av_realloc(void *ptr, unsigned int size)
#endif #endif
/* let's disallow possible ambiguous cases */ /* let's disallow possible ambiguous cases */
if(size > INT_MAX) if(size > (INT_MAX-16) )
return NULL; return NULL;
#ifdef MEMALIGN_HACK #ifdef MEMALIGN_HACK
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment