From 867e49980f4c2ea953ce5cd77dcb56bffc35351c Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 24 Sep 2024 10:54:17 +0900 Subject: [PATCH] Fix some dodgy shifts While I guess ubsan is right that shifting a 1 bit into the sign of an int can cause problems, but that's assuming the int is numeric. And it doesn't help that unsigned char promotes to int instead of unsigned int. --- libs/client/hud.c | 2 +- libs/util/mdfour.c | 2 +- nq/source/cl_parse.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/client/hud.c b/libs/client/hud.c index a183a76d2..3ea75a46d 100644 --- a/libs/client/hud.c +++ b/libs/client/hud.c @@ -732,7 +732,7 @@ draw_sigils (view_t view, void *data) { for (int i = 0; i < 4; i++) { view_t sigil = View_GetChild (view, i); - if (sbar_stats[STAT_ITEMS] & (1 << (28 + i))) { + if (sbar_stats[STAT_ITEMS] & (1u << (28 + i))) { sbar_setcomponent (sigil, canvas_pic, &sb_sigil[i]); } else { sbar_remcomponent (sigil, canvas_pic); diff --git a/libs/util/mdfour.c b/libs/util/mdfour.c index f77fa0db7..7874710d0 100644 --- a/libs/util/mdfour.c +++ b/libs/util/mdfour.c @@ -156,7 +156,7 @@ copy64 (uint32_t * M, const unsigned char *in) int i; for (i = 0; i < 16; i++) - M[i] = (in[i * 4 + 3] << 24) | (in[i * 4 + 2] << 16) | + M[i] = ((uint32_t) in[i * 4 + 3] << 24) | (in[i * 4 + 2] << 16) | (in[i * 4 + 1] << 8) | (in[i * 4 + 0] << 0); } diff --git a/nq/source/cl_parse.c b/nq/source/cl_parse.c index 01726868f..1fa3e2bf1 100644 --- a/nq/source/cl_parse.c +++ b/nq/source/cl_parse.c @@ -593,7 +593,7 @@ CL_ParseClientdata (void) if (cl.stats[STAT_ITEMS] != i) { // set flash times for (j = 0; j < 32; j++) - if ((i & (1 << j)) && !(cl.stats[STAT_ITEMS] & (1 << j))) + if ((i & (1u << j)) && !(cl.stats[STAT_ITEMS] & (1u << j))) cl.item_gettime[j] = cl.time; cl.stats[STAT_ITEMS] = i; #define IT_POWER (IT_QUAD | IT_SUIT | IT_INVULNERABILITY | IT_INVISIBILITY)