diff options
author | Herve W <H.O.W.aka.V+ffmpeg@gmail.com> | 2006-06-30 08:00:01 +0000 |
---|---|---|
committer | Guillaume Poirier <gpoirier@mplayerhq.hu> | 2006-06-30 08:00:01 +0000 |
commit | a9493601638b048c44751956d2360f215918800c (patch) | |
tree | 19720b7ab05d77cc14d52922f33f94a94f649698 /libavcodec/mem.c | |
parent | 3a6fc8faf35c84896f069c55e666120807ce65df (diff) | |
download | ffmpeg-a9493601638b048c44751956d2360f215918800c.tar.gz |
* 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
Diffstat (limited to 'libavcodec/mem.c')
-rw-r--r-- | libavcodec/mem.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/libavcodec/mem.c b/libavcodec/mem.c index b7a2ba6921..118463ba0e 100644 --- a/libavcodec/mem.c +++ b/libavcodec/mem.c @@ -50,11 +50,13 @@ void *av_malloc(unsigned int size) #endif /* let's disallow possible ambiguous cases */ - if(size > INT_MAX) + if(size > (INT_MAX-16) ) return NULL; #ifdef MEMALIGN_HACK - ptr = malloc(size+16+1); + ptr = malloc(size+16); + if(!ptr) + return ptr; diff= ((-(long)ptr - 1)&15) + 1; ptr += diff; ((char*)ptr)[-1]= diff; @@ -104,7 +106,7 @@ void *av_realloc(void *ptr, unsigned int size) #endif /* let's disallow possible ambiguous cases */ - if(size > INT_MAX) + if(size > (INT_MAX-16) ) return NULL; #ifdef MEMALIGN_HACK |