SDL_blit: Fix undefined bitshift operations
Arithmatic operations promote Uint8 to signed int. If the top bit of a Uint8 is set, and it is left shifted 24 places, then the result is not representable in a signed 32 bit int. This would be undefined behaviour on systems where int is 32 bits.
parent
032fa681a8
commit
e2dbed9cfe
|
@ -2183,7 +2183,7 @@ Blit4to4MaskAlpha(SDL_BlitInfo * info)
|
||||||
|
|
||||||
if (dstfmt->Amask) {
|
if (dstfmt->Amask) {
|
||||||
/* RGB->RGBA, SET_ALPHA */
|
/* RGB->RGBA, SET_ALPHA */
|
||||||
Uint32 mask = (info->a >> dstfmt->Aloss) << dstfmt->Ashift;
|
Uint32 mask = ((Uint32)info->a >> dstfmt->Aloss) << dstfmt->Ashift;
|
||||||
|
|
||||||
while (height--) {
|
while (height--) {
|
||||||
/* *INDENT-OFF* */
|
/* *INDENT-OFF* */
|
||||||
|
@ -2632,7 +2632,7 @@ BlitNtoNKey(SDL_BlitInfo * info)
|
||||||
|
|
||||||
if (dstfmt->Amask) {
|
if (dstfmt->Amask) {
|
||||||
/* RGB->RGBA, SET_ALPHA */
|
/* RGB->RGBA, SET_ALPHA */
|
||||||
Uint32 mask = info->a << dstfmt->Ashift;
|
Uint32 mask = ((Uint32)info->a) << dstfmt->Ashift;
|
||||||
while (height--) {
|
while (height--) {
|
||||||
/* *INDENT-OFF* */
|
/* *INDENT-OFF* */
|
||||||
DUFFS_LOOP(
|
DUFFS_LOOP(
|
||||||
|
@ -3059,7 +3059,7 @@ Blit_3or4_to_3or4__same_rgb(SDL_BlitInfo * info)
|
||||||
|
|
||||||
if (dstfmt->Amask) {
|
if (dstfmt->Amask) {
|
||||||
/* SET_ALPHA */
|
/* SET_ALPHA */
|
||||||
Uint32 mask = info->a << dstfmt->Ashift;
|
Uint32 mask = ((Uint32)info->a) << dstfmt->Ashift;
|
||||||
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||||
int i0 = 0, i1 = 1, i2 = 2;
|
int i0 = 0, i1 = 1, i2 = 2;
|
||||||
#else
|
#else
|
||||||
|
@ -3148,7 +3148,7 @@ Blit_3or4_to_3or4__inversed_rgb(SDL_BlitInfo * info)
|
||||||
Uint8 s0 = src[i0];
|
Uint8 s0 = src[i0];
|
||||||
Uint8 s1 = src[i1];
|
Uint8 s1 = src[i1];
|
||||||
Uint8 s2 = src[i2];
|
Uint8 s2 = src[i2];
|
||||||
Uint32 alphashift = src[i3] << dstfmt->Ashift;
|
Uint32 alphashift = ((Uint32)src[i3]) << dstfmt->Ashift;
|
||||||
/* inversed, compared to Blit_3or4_to_3or4__same_rgb */
|
/* inversed, compared to Blit_3or4_to_3or4__same_rgb */
|
||||||
*dst32 = (s0 << 16) | (s1 << 8) | (s2) | alphashift;
|
*dst32 = (s0 << 16) | (s1 << 8) | (s2) | alphashift;
|
||||||
dst += 4;
|
dst += 4;
|
||||||
|
@ -3160,7 +3160,7 @@ Blit_3or4_to_3or4__inversed_rgb(SDL_BlitInfo * info)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* SET_ALPHA */
|
/* SET_ALPHA */
|
||||||
Uint32 mask = info->a << dstfmt->Ashift;
|
Uint32 mask = ((Uint32)info->a) << dstfmt->Ashift;
|
||||||
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
||||||
int i0 = 0, i1 = 1, i2 = 2;
|
int i0 = 0, i1 = 1, i2 = 2;
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Reference in New Issue