]> git.lyx.org Git - lyx.git/commitdiff
Fix signed integer overflow on x = 0, detected by GCC sanitizer
authorYuriy Skalko <yuriy.skalko@gmail.com>
Thu, 26 Nov 2020 21:01:18 +0000 (23:01 +0200)
committerYuriy Skalko <yuriy.skalko@gmail.com>
Fri, 27 Nov 2020 10:17:22 +0000 (12:17 +0200)
src/support/lstrings.cpp

index f0e79b88b39bf2d64efafbc0f87f565cb85d5688..9aac66a7542616023220622b19c741130a7c5dc8 100644 (file)
@@ -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");