From f73af1a67d5299c048782cd281e99f02ef471081 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Mon, 12 Jun 2023 15:12:33 +0200 Subject: [PATCH] Fix negative shift value UB --- include/boost/charconv/detail/emulated128.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/boost/charconv/detail/emulated128.hpp b/include/boost/charconv/detail/emulated128.hpp index 8d9fc53..2c461de 100644 --- a/include/boost/charconv/detail/emulated128.hpp +++ b/include/boost/charconv/detail/emulated128.hpp @@ -722,7 +722,11 @@ BOOST_CHARCONV_CXX14_CONSTEXPR void div_impl(uint128 lhs, uint128 rhs, uint128& uint128 denom = rhs; quotient = 0U; - const int shift = high_bit(lhs) - high_bit(rhs); + std::int32_t shift = high_bit(lhs) - high_bit(rhs); + if (shift < 0) + { + shift = 32 - shift; + } denom <<= shift; for (int i = 0; i <= shift; ++i)