Skip to content

Commit

Permalink
Fix sanitizer reports: excessive shift, signed integer overflow (2)
Browse files Browse the repository at this point in the history
Fixes runtime error: left shift of X by Y places cannot be represented in type 'int'

Signed-off-by: Alexandr Pashchenko <[email protected]>
  • Loading branch information
appashchenko committed Aug 4, 2024
1 parent a6eec48 commit 6911aed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/formats/jpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ enum loader_status decode_jpeg(struct image* ctx, const uint8_t* data,
uint32_t* pixel = (uint32_t*)line;
for (int x = jpg.output_width - 1; x >= 0; --x) {
const uint8_t src = *(line + x);
pixel[x] = (0xff << 24) | src << 16 | src << 8 | src;
pixel[x] = ((argb_t)0xff << 24) | (argb_t)src << 16 |
(argb_t)src << 8 | src;
}
}

Expand All @@ -86,7 +87,8 @@ enum loader_status decode_jpeg(struct image* ctx, const uint8_t* data,
uint32_t* pixel = (uint32_t*)line;
for (int x = jpg.output_width - 1; x >= 0; --x) {
const uint8_t* src = line + x * 3;
pixel[x] = (0xff << 24) | src[0] << 16 | src[1] << 8 | src[2];
pixel[x] = ((argb_t)0xff << 24) | (argb_t)src[0] << 16 |
(argb_t)src[1] << 8 | src[2];
}
}
#endif // LIBJPEG_TURBO_VERSION
Expand Down
8 changes: 4 additions & 4 deletions src/pixmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ typedef uint32_t argb_t;
#define ARGB_GET_B(c) (((c) >> ARGB_B_SHIFT) & 0xff)

// create argb_t from channel value
#define ARGB_SET_A(a) (((a) & 0xff) << ARGB_A_SHIFT)
#define ARGB_SET_R(r) (((r) & 0xff) << ARGB_R_SHIFT)
#define ARGB_SET_G(g) (((g) & 0xff) << ARGB_G_SHIFT)
#define ARGB_SET_B(b) (((b) & 0xff) << ARGB_B_SHIFT)
#define ARGB_SET_A(a) (((argb_t)(a) & 0xff) << ARGB_A_SHIFT)
#define ARGB_SET_R(r) (((argb_t)(r) & 0xff) << ARGB_R_SHIFT)
#define ARGB_SET_G(g) (((argb_t)(g) & 0xff) << ARGB_G_SHIFT)
#define ARGB_SET_B(b) (((argb_t)(b) & 0xff) << ARGB_B_SHIFT)

// convert ABGR to ARGB
#define ABGR_TO_ARGB(c) \
Expand Down

0 comments on commit 6911aed

Please sign in to comment.