# HG changeset patch # User gpoirier # Date 1151654401 0 # Node ID e9614cf8ac92744fa2ac74758ae650901cf959cb # Parent b8996cc5ccae84d9f0e58b6b7420bfb10a65a300 * 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 diff -r b8996cc5ccae -r e9614cf8ac92 mem.c --- a/mem.c Fri Jun 30 07:50:30 2006 +0000 +++ b/mem.c Fri Jun 30 08:00:01 2006 +0000 @@ -50,11 +50,13 @@ #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 @@ #endif /* let's disallow possible ambiguous cases */ - if(size > INT_MAX) + if(size > (INT_MAX-16) ) return NULL; #ifdef MEMALIGN_HACK