mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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:
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user