Skip to content

Commit

Permalink
Remove undefined behavior
Browse files Browse the repository at this point in the history
* Taking the negative of a signed negative is UB, but
  taking the negative of an unsigned is not.
  • Loading branch information
HowardHinnant committed Sep 15, 2022
1 parent b57bc62 commit 7e10665
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ripple/basics/impl/Number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ Number::normalize()
return;
}
bool const negative = (mantissa_ < 0);
if (negative)
mantissa_ = -mantissa_;
auto m = static_cast<std::make_unsigned_t<rep>>(mantissa_);
if (negative)
m = -m;
while ((m < minMantissa) && (exponent_ > minExponent))
{
m *= 10;
Expand Down

0 comments on commit 7e10665

Please sign in to comment.