[FFmpeg-devel] [PATCH] av_malloc() workaround for QNX platform
michaelni at gmx.at
Thu Feb 7 18:00:10 CET 2013
On Thu, Feb 07, 2013 at 05:33:15PM +0200, Mike Gorchak wrote:
> > I looked through the memalign hack code, and it seems to work as expected.
> > If ptr returned by malloc is already aligned, diff will equal ALIGN,
> > and the returned pointer is advanced by ALIGN, and there is plenty
> > space to write the diff.
> Here is step-by-step sample:
> ptr = malloc(size + ALIGN);
> Let here will be: ptr = 0x0000FE0 - 32 bytes aligned and size also 32 bytes.
> diff = ((~(long)ptr)&(ALIGN - 1)) + 1;
> Let calculate diff manually: diff = (0xFFFF01F & 0x0000001F) +1, diff
> = 0x00000020 (32)
> ptr = (char *)ptr + diff;
> ptr=0x0000FE0 + 0x00000020 = 0x00010000
> So ptr now points to the beyond of the allocated memory. I was wrong
> that problem with [-1] write, it is a problem with returned pointer.
0x0000FE0 + 0x00000020
0x1000 not 0x10000
and you stated above "32 bytes aligned and size also 32 bytes"
that makes an allocation of 64bytes due to
"ptr = malloc(size + ALIGN);"
thus 0x1000 up to 0x101F is allocated and there are 32bytes available
at the pointer as requested
if instead you meant 32bytes aligned and a size of 0" then you
should not expect to get more than 0 bytes
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
You can kill me, but you cannot change the truth.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 198 bytes
Desc: Digital signature
More information about the ffmpeg-devel