[FFmpeg-devel] Patch: avoid "void * " in pointer calculate

mvplayer ffmpeg
Thu Feb 14 02:01:08 CET 2008


On Feb 14, 2008 1:35 AM, Michael Niedermayer <michaelni at gmx.at> wrote:

> On Wed, Feb 13, 2008 at 09:29:46PM +0800, mvplayer wrote:
> > As $subject
> [...]
> > -void *av_realloc(void *ptr, unsigned int size)
> > +void *av_realloc(void *ptr1, unsigned int size)
> >  {
> >  #ifdef CONFIG_MEMALIGN_HACK
> >      int diff;
> > +    char *ptr = ptr1;
> >  #endif
> >
> >      /* let's disallow possible ambiguous cases */
> > @@ -105,9 +106,9 @@
> >      //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;
> > +    return (char*)realloc(ptr - diff, size + diff) + diff;
> >  #else
> > -    return realloc(ptr, size);
> > +    return realloc(ptr1, size);
> >  #endif
>
> this can be done simpler, i dont see why you would need an extra var
>
> Sure!

a clean version arrived!

Index: mem.c
===================================================================
--- mem.c ?r11927?
+++ mem.c ?working?
@@ -55,7 +55,7 @@
     if(!ptr)
         return ptr;
     diff= ((-(long)ptr - 1)&15) + 1;
-    ptr += diff;
+    ptr = (char*)ptr + diff;
     ((char*)ptr)[-1]= diff;
 #elif defined (HAVE_MEMALIGN)
     ptr = memalign(16,size);
@@ -105,7 +105,7 @@
     //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;
+    return (char*)realloc((char*)ptr - diff, size + diff) + diff;
 #else
     return realloc(ptr, size);
 #endif
@@ -116,7 +116,7 @@
     /* XXX: this test should not be needed on most libcs */
     if (ptr)
 #ifdef CONFIG_MEMALIGN_HACK
-        free(ptr - ((char*)ptr)[-1]);
+        free((char*)ptr - ((char*)ptr)[-1]);
 #else
         free(ptr);
 #endif


----------------------------------------
Inspired by http://www.mvplayer.net




More information about the ffmpeg-devel mailing list