From 9be45d358ac45b2e9897d49afbaaf4f9031b2a4e Mon Sep 17 00:00:00 2001 From: Junekey Jeon Date: Tue, 2 Apr 2024 12:20:30 -0700 Subject: [PATCH] Avoid unsigned overflow when computing the full-bit mask --- include/dragonbox/dragonbox.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/dragonbox/dragonbox.h b/include/dragonbox/dragonbox.h index bf74d01..edb8dbb 100644 --- a/include/dragonbox/dragonbox.h +++ b/include/dragonbox/dragonbox.h @@ -375,7 +375,7 @@ namespace jkj { // Shift the obtained signed significand bits to the left by 1 to remove the sign bit. static constexpr carrier_uint remove_sign_bit_and_shift(carrier_uint u) noexcept { constexpr auto mask = - carrier_uint(((carrier_uint(1) << (Format::total_bits - 1)) << 1) - 1u); + carrier_uint((((carrier_uint(1) << (Format::total_bits - 1)) - 1u) << 1) | 1u); return carrier_uint((carrier_uint(u) << 1) & mask); } @@ -411,7 +411,7 @@ namespace jkj { } static constexpr bool has_all_zero_significand_bits(carrier_uint u) noexcept { constexpr auto mask = - carrier_uint(((carrier_uint(1) << (Format::total_bits - 1)) << 1) - 1u); + carrier_uint((((carrier_uint(1) << (Format::total_bits - 1)) - 1u) << 1) | 1u); return ((u << 1) & mask) == 0; } static constexpr bool has_even_significand_bits(carrier_uint u) noexcept {