From c24c32bf71b8e64bd0d36e511f554e1f6c015842 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Wed, 22 Nov 2017 15:34:09 +0100 Subject: ofz#4366 Divide-by-zero Change-Id: I3d0eb3bb6a69d09e71ce8bf91051f66e204eb0df Reviewed-on: https://gerrit.libreoffice.org/45098 Reviewed-by: Eike Rathke Tested-by: Jenkins --- sal/rtl/math.cxx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'sal') diff --git a/sal/rtl/math.cxx b/sal/rtl/math.cxx index 997280784351..96c5843dcfea 100644 --- a/sal/rtl/math.cxx +++ b/sal/rtl/math.cxx @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -365,8 +366,15 @@ inline void doubleToString(typename T::String ** pResult, int nExp = 0; if ( fValue > 0.0 ) { - nExp = static_cast< int >(floor(log10(fValue))); - fValue /= getN10Exp(nExp); + // Cap nExp at a small value beyond which "fValue /= N10Exp" would lose precision (or N10Exp + // might even be zero); that will produce output with the decimal point in a non-normalized + // position, but the current quality of output for such small values is probably abysmal, + // anyway: + nExp = std::max( + static_cast< int >(floor(log10(fValue))), std::numeric_limits::min_exponent10); + double const N10Exp = getN10Exp(nExp); + assert(N10Exp != 0); + fValue /= N10Exp; } switch (eFormat) -- cgit