Skip to content

Commit a2ef220

Browse files
committed
Cast before additional shifting
1 parent 1d4cda6 commit a2ef220

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

src/libImaging/Access.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static void
6464
get_pixel_16L(Imaging im, int x, int y, void *color) {
6565
UINT8 *in = (UINT8 *)&im->image[y][x + x];
6666
#ifdef WORDS_BIGENDIAN
67-
UINT16 out = in[0] + (in[1] << 8);
67+
UINT16 out = in[0] + ((UINT16)in[1] << 8);
6868
memcpy(color, &out, sizeof(out));
6969
#else
7070
memcpy(color, in, sizeof(UINT16));
@@ -77,7 +77,7 @@ get_pixel_16B(Imaging im, int x, int y, void *color) {
7777
#ifdef WORDS_BIGENDIAN
7878
memcpy(color, in, sizeof(UINT16));
7979
#else
80-
UINT16 out = in[1] + (in[0] << 8);
80+
UINT16 out = in[1] + ((UINT16)in[0] << 8);
8181
memcpy(color, &out, sizeof(out));
8282
#endif
8383
}
@@ -91,7 +91,8 @@ static void
9191
get_pixel_32L(Imaging im, int x, int y, void *color) {
9292
UINT8 *in = (UINT8 *)&im->image[y][x * 4];
9393
#ifdef WORDS_BIGENDIAN
94-
INT32 out = in[0] + (in[1] << 8) + (in[2] << 16) + (in[3] << 24);
94+
INT32 out =
95+
in[0] + ((INT32)in[1] << 8) + ((INT32)in[2] << 16) + ((INT32)in[3] << 24);
9596
memcpy(color, &out, sizeof(out));
9697
#else
9798
memcpy(color, in, sizeof(INT32));
@@ -104,7 +105,8 @@ get_pixel_32B(Imaging im, int x, int y, void *color) {
104105
#ifdef WORDS_BIGENDIAN
105106
memcpy(color, in, sizeof(INT32));
106107
#else
107-
INT32 out = in[3] + (in[2] << 8) + (in[1] << 16) + (in[0] << 24);
108+
INT32 out =
109+
in[3] + ((INT32)in[2] << 8) + ((INT32)in[1] << 16) + ((INT32)in[0] << 24);
108110
memcpy(color, &out, sizeof(out));
109111
#endif
110112
}

src/libImaging/BcnEncode.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ decode_565(UINT16 x) {
3636

3737
static UINT16
3838
encode_565(rgba item) {
39-
UINT8 r, g, b;
40-
r = item.color[0] >> (8 - 5);
41-
g = item.color[1] >> (8 - 6);
42-
b = item.color[2] >> (8 - 5);
39+
UINT16 r = item.color[0] >> (8 - 5);
40+
UINT8 g = item.color[1] >> (8 - 6);
41+
UINT8 b = item.color[2] >> (8 - 5);
4342
return (r << (5 + 6)) | (g << 5) | b;
4443
}
4544

@@ -157,7 +156,8 @@ encode_bc1_color(Imaging im, ImagingCodecState state, UINT8 *dst, int separate_a
157156
static void
158157
encode_bc2_block(Imaging im, ImagingCodecState state, UINT8 *dst) {
159158
int i, j;
160-
UINT8 block[16], current_alpha;
159+
UINT8 block[16];
160+
UINT32 current_alpha;
161161
for (i = 0; i < 4; i++) {
162162
for (j = 0; j < 4; j++) {
163163
int x = state->x + i * im->pixelsize;

src/libImaging/FliDecode.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616

1717
#include "Imaging.h"
1818

19-
#define I16(ptr) ((ptr)[0] + ((ptr)[1] << 8))
19+
#define I16(ptr) ((ptr)[0] + ((int)(ptr)[1] << 8))
2020

21-
#define I32(ptr) ((ptr)[0] + ((ptr)[1] << 8) + ((ptr)[2] << 16) + ((ptr)[3] << 24))
21+
#define I32(ptr) \
22+
((ptr)[0] + ((INT32)(ptr)[1] << 8) + ((INT32)(ptr)[2] << 16) + \
23+
((INT32)(ptr)[3] << 24))
2224

2325
#define ERR_IF_DATA_OOB(offset) \
2426
if ((data + (offset)) > ptr + bytes) { \

src/libImaging/GetBBox.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ ImagingGetExtrema(Imaging im, void *extrema) {
212212
UINT16 v;
213213
UINT8 *pixel = *im->image8;
214214
#ifdef WORDS_BIGENDIAN
215-
v = pixel[0] + (pixel[1] << 8);
215+
v = pixel[0] + ((UINT16)pixel[1] << 8);
216216
#else
217217
memcpy(&v, pixel, sizeof(v));
218218
#endif
@@ -221,7 +221,7 @@ ImagingGetExtrema(Imaging im, void *extrema) {
221221
for (x = 0; x < im->xsize; x++) {
222222
pixel = (UINT8 *)im->image[y] + x * sizeof(v);
223223
#ifdef WORDS_BIGENDIAN
224-
v = pixel[0] + (pixel[1] << 8);
224+
v = pixel[0] + ((UINT16)pixel[1] << 8);
225225
#else
226226
memcpy(&v, pixel, sizeof(v));
227227
#endif

0 commit comments

Comments
 (0)