From 337cf4bfd5383cc42581e7f158e73ea762f44b5f Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Thu, 19 Feb 2026 15:44:54 +0900 Subject: [PATCH] etc.c: fix undefined behavior in WORDBOX_FLOAT_ADDEND Left-shifting a negative int64_t is undefined behavior in C. Cast to uint64_t before the shift to produce the same bit pattern using well-defined unsigned arithmetic. Co-authored-by: Claude --- src/etc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/etc.c b/src/etc.c index 18a71a935..5a1104786 100644 --- a/src/etc.c +++ b/src/etc.c @@ -207,7 +207,7 @@ mrb_obj_id(mrb_value obj) #define WORDBOX_FLOAT_ROTATE 3 #define WORDBOX_FLOAT_EXP_MIN (1023 - 255) /* 768 */ #define WORDBOX_FLOAT_EXP_MAX (1023 + 256) /* 1279 */ -#define WORDBOX_FLOAT_ADDEND ((uint64_t)((int64_t)(WORDBOX_FLOAT_EXP_MIN - (WORDBOX_FLOAT_FLAG << 9)) << 52)) +#define WORDBOX_FLOAT_ADDEND ((uint64_t)(WORDBOX_FLOAT_EXP_MIN - (WORDBOX_FLOAT_FLAG << 9)) << 52) /* sentinel values for special floats (all have & 3 == 2) */ #define WORDBOX_FLOAT_PZERO 0x02 /* +0.0 */