diff options
author | Mike Melanson <mike@multimedia.cx> | 2005-04-19 05:16:45 +0000 |
---|---|---|
committer | Mike Melanson <mike@multimedia.cx> | 2005-04-19 05:16:45 +0000 |
commit | 97c50cb77949856573d7f5f5a3c28cb73e61e011 (patch) | |
tree | 2dbabcbb9009b09d66789498ce1d2451a4b39bc0 /src/libffmpeg/libavcodec/mem.c | |
parent | 19e7199dad84489aa49e3b2dd5c0e45657ec0fb8 (diff) | |
download | xine-lib-97c50cb77949856573d7f5f5a3c28cb73e61e011.tar.gz xine-lib-97c50cb77949856573d7f5f5a3c28cb73e61e011.tar.bz2 |
sync to FFmpeg build 4752
CVS patchset: 7463
CVS date: 2005/04/19 05:16:45
Diffstat (limited to 'src/libffmpeg/libavcodec/mem.c')
-rw-r--r-- | src/libffmpeg/libavcodec/mem.c | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/libffmpeg/libavcodec/mem.c b/src/libffmpeg/libavcodec/mem.c index c5ca166d3..462d674e4 100644 --- a/src/libffmpeg/libavcodec/mem.c +++ b/src/libffmpeg/libavcodec/mem.c @@ -45,8 +45,20 @@ void *av_malloc(unsigned int size) { void *ptr; +#ifdef MEMALIGN_HACK + int diff; +#endif + + /* lets disallow possible ambiguous cases */ + if(size > INT_MAX) + return NULL; -#if defined (HAVE_MEMALIGN) +#ifdef MEMALIGN_HACK + ptr = malloc(size+16+1); + diff= ((-(int)ptr - 1)&15) + 1; + ptr += diff; + ((char*)ptr)[-1]= diff; +#elif defined (HAVE_MEMALIGN) ptr = memalign(16,size); /* Why 64? Indeed, we should align it: @@ -87,7 +99,22 @@ void *av_malloc(unsigned int size) */ void *av_realloc(void *ptr, unsigned int size) { +#ifdef MEMALIGN_HACK + int diff; +#endif + + /* lets disallow possible ambiguous cases */ + if(size > INT_MAX) + return NULL; + +#ifdef MEMALIGN_HACK + //FIXME this isnt aligned correctly though it probably isnt needed + if(!ptr) return av_malloc(size); + diff= ((char*)ptr)[-1]; + return realloc(ptr - diff, size + diff) + diff; +#else return realloc(ptr, size); +#endif } /* NOTE: ptr = NULL is explicetly allowed */ @@ -95,6 +122,10 @@ void av_free(void *ptr) { /* XXX: this test should not be needed on most libcs */ if (ptr) +#ifdef MEMALIGN_HACK + free(ptr - ((char*)ptr)[-1]); +#else free(ptr); +#endif } |