summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-11-22 15:34:09 +0100
committerStephan Bergmann <sbergman@redhat.com>2017-11-22 23:59:52 +0100
commitc24c32bf71b8e64bd0d36e511f554e1f6c015842 (patch)
treefbc3070205e79b86dd1c09b27f66515000e8a8e9 /sal
parent54e1441949b83a76eecd02f2839693697773f711 (diff)
ofz#4366 Divide-by-zero
Change-Id: I3d0eb3bb6a69d09e71ce8bf91051f66e204eb0df Reviewed-on: https://gerrit.libreoffice.org/45098 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'sal')
-rw-r--r--sal/rtl/math.cxx12
1 files changed, 10 insertions, 2 deletions
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)