summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2018-07-29 13:22:00 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2018-07-29 13:22:00 +0100
commitf8cae937dd67a7bca394000854b7c5f38330022b (patch)
tree0c052e065b04ebb1d1a0e626c51f70f8256afdce
parentc8f5b9a37174f7184db1e3e57c0f588a59306c90 (diff)
downloadlibrosprite-f8cae937dd67a7bca394000854b7c5f38330022b.tar.gz
librosprite-f8cae937dd67a7bca394000854b7c5f38330022b.tar.bz2
Decode: Fix undefined shifts found by ubsan.
runtime error: left shift of 255 by 24 places cannot be represented in type 'int'
-rw-r--r--src/librosprite.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/librosprite.c b/src/librosprite.c
index b382ce0..7cfcaaa 100644
--- a/src/librosprite.c
+++ b/src/librosprite.c
@@ -21,7 +21,11 @@
/**
* Reads four bytes, 00, 11, 22 and 33, of a byte array b to give 0x33221100.
*/
-#define BTUINT(b) (b[0] | (b[1] << 8) | (b[2] << 16) | (b[3] << 24))
+#define BTUINT(b) \
+ ((unsigned)b[0] | \
+ ((unsigned)b[1] << 8) | \
+ ((unsigned)b[2] << 16) | \
+ ((unsigned)b[3] << 24))
/**
* Reverse the byte order of a word such that 0xAABBCCDD becomes 0xDDCCBBAA.
@@ -559,7 +563,7 @@ static rosprite_error rosprite_load_high_color(uint8_t* image_in, uint8_t* mask,
uint32_t currentByteIndex = 0;
uint32_t j, x, y, x_pixels, pixel;
bool has_alpha_pixel_data = false;
- uint8_t b;
+ uint32_t b;
bool old_has_alpha;
if (sprite->has_mask) {
@@ -809,9 +813,9 @@ static uint32_t rosprite_upscale_color(uint32_t pixel, struct rosprite_mode* mod
assert(green < 32);
assert(blue < 32);
- pixel = (sprite_16bpp_translate[red] << 24)
- | (sprite_16bpp_translate[green] << 16)
- | (sprite_16bpp_translate[blue] << 8);
+ pixel = ((uint32_t)sprite_16bpp_translate[red] << 24)|
+ ((uint32_t)sprite_16bpp_translate[green] << 16)|
+ ((uint32_t)sprite_16bpp_translate[blue] << 8);
}
break;
case 8: