Author: michael Date: Sun Aug 13 23:09:00 2006 New Revision: 5996 Modified: trunk/libavutil/mem.c Log: trying to fix av_realloc() Modified: trunk/libavutil/mem.c ============================================================================== --- trunk/libavutil/mem.c (original) +++ trunk/libavutil/mem.c Sun Aug 13 23:09:00 2006 @@ -50,7 +50,7 @@ #endif /* let's disallow possible ambiguous cases */ - if(size > (INT_MAX-16) ) + if(size > (INT_MAX-16) || !size) return NULL; #ifdef MEMALIGN_HACK @@ -109,14 +109,16 @@ #ifndef MEMALIGN_HACK ptr= realloc(ptr, size); - if(((int)ptr&15) || !ptr) +assert(((int)((void*)0)&15) == 0); //for the null pointer pedants + if(!((int)ptr&15)) return ptr; #endif ptr2= av_malloc(size); if(ptr && ptr2) memcpy(ptr2, ptr, size); - av_free(ptr); + if(ptr2 || !size) + av_free(ptr); return ptr2; }
Hello, On Sun, Aug 13, 2006 at 11:09:00PM +0200, michael wrote:
#ifndef MEMALIGN_HACK ptr= realloc(ptr, size); - if(((int)ptr&15) || !ptr) +assert(((int)((void*)0)&15) == 0); //for the null pointer pedants + if(!((int)ptr&15)) return ptr; #endif
ptr2= av_malloc(size); if(ptr && ptr2) memcpy(ptr2, ptr, size);
This would have to be the minimum of the size for ptr and ptr2, unfortunately we don't know that for ptr. No idea what would be a good way to fix it... Greetings, Reimar D?ffinger
Hi, On 15/08/06, Reimar D?ffinger wrote:
Hello, On Sun, Aug 13, 2006 at 11:09:00PM +0200, michael wrote: [...]
ptr2= av_malloc(size); if(ptr && ptr2) memcpy(ptr2, ptr, size);
This would have to be the minimum of the size for ptr and ptr2, unfortunately we don't know that for ptr.
I wondered about that, but I figured Michael would know what could be allowed.
No idea what would be a good way to fix it...
Perhaps we could think of some options ? - save the allocated size as well as 'diff' in the MEMALIGN_HACK code path - always realloc() first, not just when MEMALIGN_HACK is NOT defined Are there any other options? -V
Hi On Tue, Aug 15, 2006 at 06:23:17PM +0200, Reimar D?ffinger wrote:
Hello, On Sun, Aug 13, 2006 at 11:09:00PM +0200, michael wrote:
#ifndef MEMALIGN_HACK ptr= realloc(ptr, size); - if(((int)ptr&15) || !ptr) +assert(((int)((void*)0)&15) == 0); //for the null pointer pedants + if(!((int)ptr&15)) return ptr; #endif
ptr2= av_malloc(size); if(ptr && ptr2) memcpy(ptr2, ptr, size);
This would have to be the minimum of the size for ptr and ptr2,
indeed
unfortunately we don't know that for ptr. No idea what would be a good way to fix it...
me neither :( ill wait a few days and if noone came up with a solution (or people start reporting segfalts) then ill reverse the aligned av_realoc() changes [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB In the past you could go to a library and read, borrow or copy any book Today you'd get arrested for mere telling someone where the library is
Hi On Tue, Aug 15, 2006 at 06:23:17PM +0200, Reimar D?ffinger wrote:
Hello, On Sun, Aug 13, 2006 at 11:09:00PM +0200, michael wrote:
#ifndef MEMALIGN_HACK ptr= realloc(ptr, size); - if(((int)ptr&15) || !ptr) +assert(((int)((void*)0)&15) == 0); //for the null pointer pedants + if(!((int)ptr&15)) return ptr; #endif
ptr2= av_malloc(size); if(ptr && ptr2) memcpy(ptr2, ptr, size);
This would have to be the minimum of the size for ptr and ptr2, unfortunately we don't know that for ptr. No idea what would be a good way to fix it...
ptr=realloc(ptr, size) (or equivalent for MEMALIGN_HACK) if(!((int)ptr&15)) return ptr; ptr2= av_malloc(size); if(ptr && ptr2) memcpy(ptr2, ptr, size); av_free(ptr); return ptr2; the difference to the old ... we realloc() first so we know that the "old" size will be equal to the new ... note, iam too lazy to test and commit this (especially before the mplayer release ...) [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB In the past you could go to a library and read, borrow or copy any book Today you'd get arrested for mere telling someone where the library is
participants (4)
-
H.O.W.aka.V+ffmpeg@gmail.com -
michaelni@gmx.at -
Reimar.Doeffinger@stud.uni-karlsruhe.de -
subversion@mplayerhq.hu