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 <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2026-02-19 15:44:54 +09:00
parent 0ed26f8352
commit 337cf4bfd5
+1 -1
View File
@@ -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 */