Does need 4 bytes alignmen in SDL_Upsample_S16LSB_2c?

There is statement in SDL_Upsample_S16LSB_2c.----------------------

const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);


cvt->rate_incr is double value, may multiply operator generate a integer
value that isn’t 4 bytes alignmnt?

If dstsize isn’t 4 bytes aligment, it will result dst accessing invalid
memory. If update to below, whether make code safer?


const int dstsize = ((int) (((double)cvt->len_cvt) * cvt->rate_incr)) & ~3;


In addition, does calculating dstsize need 4 bytes aligment in
SDL_Downsample_S16LSB_2c?

In the future, please post the file path

There is statement in SDL_Upsample_S16LSB_2c.****

----------------------****

const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);****

----------------------****

cvt->rate_incr is double value, may multiply operator generate a integer
value that isn’t 4 bytes alignmnt? ****

**

I think I know what you’re trying to say, but your getting your terms a bit
confused here. A compiler won’t generate an integer value that isn’t
aligned to its natural boundaries, no. This array is indexing 16-bit
values, which means it will only fault if the address is not 2-byte
aligned. I guess it depends on the result of the multiplication. It would
seem that it would be safer to ensure that it starts on the nearest sample,
but ANDing the address isn’t the right way, because you don’t want to just
ensure it doesn’t fault, but you want to ensure that if you do have to
round down, you pick the beginning of a sample, not the middle, which would
reverse the L/R channels in this case. The fact that this hasn’t been hit
yet makes me think that there might be something special about the way
these values are picked. Then again, it might be a legitimate bug. Anyone
more familiar with how this part of the code have any insights?On Tue, Feb 21, 2012 at 3:54 AM, li zhuo wrote:

**

If dstsize isn’t 4 bytes aligment, it will result dst accessing invalid
memory. If update to below, whether make code safer?****

----------------------****

const int dstsize = ((int) (((double)cvt->len_cvt) * cvt->rate_incr)) & ~3;


----------------------****


In addition, does calculating dstsize need 4 bytes aligment in
SDL_Downsample_S16LSB_2c?****


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org