[FFmpeg-devel] [PATCH] mingw memalign hack fix

David DeHaven dave
Thu Nov 27 00:28:19 CET 2008


SSE2 code was segfaulting on my MinGW builds, turns out blocks being  
av_realloc'd were losing their alignment. This patch fixes that.

I don't know if other platforms need the memalign hack so I can only  
test Windows builds. None of the others I build for do (Mac OS X/ 
Darwin and Linux). It uses the same alignment code as av_malloc (cut-n- 
paste) so I can't imagine it would break anything.

-DrD-

Index: libavutil/mem.c
===================================================================
--- libavutil/mem.c	(revision 15942)
+++ libavutil/mem.c	(working copy)
@@ -102,10 +102,16 @@
          return NULL;

  #ifdef CONFIG_MEMALIGN_HACK
-    //FIXME this isn't aligned correctly, though it probably isn't  
needed
      if(!ptr) return av_malloc(size);
      diff= ((char*)ptr)[-1];
-    return (char*)realloc((char*)ptr - diff, size + diff) + diff;
+
+    // diff is only valid on exit IF the pointer remains the same, so  
we realign the "new" pointer
+    ptr = realloc((char*)ptr - diff, size + diff);
+    if(!ptr) return ptr;
+    diff = ((-(long)ptr - 1)&15) + 1;
+    ptr = (char*)ptr + diff;
+    ((char*)ptr)[-1]= diff;
+    return ptr;
  #else
      return realloc(ptr, size);
  #endif





More information about the ffmpeg-devel mailing list