sal/rtl/math.cxx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
New commits: commit c24c32bf71b8e64bd0d36e511f554e1f6c015842 Author: Stephan Bergmann <sberg...@redhat.com> Date: Wed Nov 22 15:34:09 2017 +0100 ofz#4366 Divide-by-zero Change-Id: I3d0eb3bb6a69d09e71ce8bf91051f66e204eb0df Reviewed-on: https://gerrit.libreoffice.org/45098 Reviewed-by: Eike Rathke <er...@redhat.com> Tested-by: Jenkins <c...@libreoffice.org> 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 <algorithm> #include <cassert> #include <float.h> +#include <limits> #include <limits.h> #include <math.h> #include <stdlib.h> @@ -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<double>::min_exponent10); + double const N10Exp = getN10Exp(nExp); + assert(N10Exp != 0); + fValue /= N10Exp; } switch (eFormat) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits