[Ffmpeg-devel] [PATCH] cosmetics and minor improvements to mem.c
Hervé W.
H.O.W.aka.V+ffmpeg
Thu Jun 29 01:28:01 CEST 2006
Hello,
This patch does some cosmetic changes and minor improvements (+16 is
enough) to av_malloc() and av_realloc().
I have a second patch that ensures alignment (to 16) in av_realloc(), would
that be something that you'd be interested in?
-V
Index: libavcodec/mem.c
===================================================================
--- libavcodec/mem.c (revision 5538)
+++ libavcodec/mem.c (working copy)
@@ -47,14 +47,19 @@
void *ptr;
#ifdef MEMALIGN_HACK
long diff;
-#endif
- /* lets disallow possible ambiguous cases */
+ /* let's disallow possible ambiguous cases */
+ if(size > (INT_MAX-16) )
+ return NULL;
+#else
if(size > INT_MAX)
return NULL;
+#endif
#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;
@@ -100,15 +105,18 @@
void *av_realloc(void *ptr, unsigned int size)
{
#ifdef MEMALIGN_HACK
- int diff;
-#endif
+ long diff;
- /* lets disallow possible ambiguous cases */
+ /* let's disallow possible ambiguous cases */
+ if(size > (INT_MAX-16) )
+ return NULL;
+#else
if(size > INT_MAX)
return NULL;
+#endif
#ifdef MEMALIGN_HACK
- //FIXME this isnt aligned correctly though it probably isnt needed
+ //FIXME this isn't aligned correctly, though it probably isn't needed
if(!ptr) return av_malloc(size);
diff= ((char*)ptr)[-1];
return realloc(ptr - diff, size + diff) + diff;
More information about the ffmpeg-devel
mailing list