This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository legacy-imlib2.
View the commit online.
commit e76d9bcf9f3aad4d60903db4e4f1d6e30f86bf2b
Author: NRK <n...@disroot.org>
AuthorDate: Fri Jan 13 12:40:25 2023 +0600
PNM loader: avoid some undefined behavior
`ptr` is a `uint8_t` pointer, which will get promoted to an `int` due to
integer promotion. and shifting a signed int by 24 places could cause
signed overflow which is undefined.
> If E1 has a signed type and nonnegative value, and E1 x 2^E2 is
> representable in the result type, then that is the resulting value;
> otherwise, the behavior is undefined.
ref: https://port70.net/~nsz/c/c99/n1256.html#6.5.7p4
---
src/modules/loaders/loader_pnm.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/modules/loaders/loader_pnm.c b/src/modules/loaders/loader_pnm.c
index 2f20688..f5a14f8 100644
--- a/src/modules/loaders/loader_pnm.c
+++ b/src/modules/loaders/loader_pnm.c
@@ -9,8 +9,8 @@
static const char *const _formats[] = { "pnm", "ppm", "pgm", "pbm", "pam" };
-typedef enum
- { BW_RAW_PACKED, BW_RAW, BW_PLAIN, GRAY_RAW, GRAY_PLAIN, RGB_RAW, RGB_PLAIN,
+typedef enum {
+ BW_RAW_PACKED, BW_RAW, BW_PLAIN, GRAY_RAW, GRAY_PLAIN, RGB_RAW, RGB_PLAIN,
XV332
} px_type;
@@ -513,8 +513,8 @@ _load(ImlibImage * im, int load_data)
for (x = 0; x < w; x++)
{
*ptr2 =
- (ptr[1] << 24) | (ptr[0] << 16) | (ptr[0] << 8) |
- ptr[0];
+ ((uint32_t)ptr[1] << 24) | (ptr[0] << 16) |
+ (ptr[0] << 8) | ptr[0];
ptr2++;
ptr += 2;
}
@@ -524,7 +524,7 @@ _load(ImlibImage * im, int load_data)
for (x = 0; x < w; x++)
{
*ptr2 =
- (((ptr[1] * 255) / v) << 24) |
+ ((uint32_t)((ptr[1] * 255) / v) << 24) |
(((ptr[0] * 255) / v) << 16) |
(((ptr[0] * 255) / v) << 8) | ((ptr[0] * 255) /
v);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.