From: Yuriy Skalko Date: Thu, 26 Nov 2020 21:01:18 +0000 (+0200) Subject: Fix signed integer overflow on x = 0, detected by GCC sanitizer X-Git-Tag: 2.4.0-alpha3~652 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=fdefff1108d43739b6631015f55fb3cc94cfed2b;p=lyx.git Fix signed integer overflow on x = 0, detected by GCC sanitizer --- diff --git a/src/support/lstrings.cpp b/src/support/lstrings.cpp index f0e79b88b3..9aac66a754 100644 --- a/src/support/lstrings.cpp +++ b/src/support/lstrings.cpp @@ -1446,8 +1446,8 @@ std::string formatFPNumber(double x) os << std::fixed; // Prevent outputs of 23.4200000000000017 but output small numbers // with at least 6 significant digits. - double const logarithm = log10(fabs(x)); - os << std::setprecision(max(6 - iround(logarithm), 0)) << x; + int const precision = (x == 0.0) ? 0 : max(6 - iround(log10(fabs(x))), 0); + os << std::setprecision(precision) << x; string result = os.str(); if (result.find('.') != string::npos) { result = rtrim(result, "0");