diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2013-12-17 16:46:17 +0100 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2014-01-03 09:54:34 +0100 |
commit | b036696da5fe6baf5eb470f43077c926f81b59f2 (patch) | |
tree | 3873825689162a52625b4e8b58620beae3535e8b /sax | |
parent | c1b46bef2fba2f539fd69554aaac11b9d63d1458 (diff) |
Avoid inaccurate floating-point computations
...otherwise at least my --disable-dbgutil --disable-debug Linux x86_64 build
failed the CppunitTest_sax_cpputest with 8999999 vs. 9000000 nanoseconds.
(cherry picked from commit 695671eb18674ea58103093b9cf31a31afe8d2fd,
incorporating follow-up fixes 71448690d7c5904df45bf98243c5bb05a99245e5
"readUnsignedNumberMaxDigits can read more than maxDigits chars" and
b9bcc9c5c10841dcdfa9ff5814344ce667678df3 "...and nDigits > 9 is harmless in
following for loop and need not be capped")
Change-Id: I05e0febf413f9f9e01227a0cc4e0f46a5243fe61
(cherry picked from commit 5bffe4dffd7496057c1fd70e46af800396f5b346)
Reviewed-on: https://gerrit.libreoffice.org/7122
Reviewed-by: Michael Stahl <mstahl@redhat.com>
Tested-by: Michael Stahl <mstahl@redhat.com>
Diffstat (limited to 'sax')
-rw-r--r-- | sax/source/tools/converter.cxx | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/sax/source/tools/converter.cxx b/sax/source/tools/converter.cxx index bc8b0c1c82b1..429f5e46dbe9 100644 --- a/sax/source/tools/converter.cxx +++ b/sax/source/tools/converter.cxx @@ -1120,9 +1120,13 @@ bool Converter::convertDuration(util::Duration& rDuration, { if (-1 != nTemp) { - const sal_Int32 nDigits = std::min<sal_Int32>(nPos - nStart, 9); - OSL_ENSURE(nDigits > 0, "bad code monkey: negative digits"); - nNanoSeconds=static_cast<double>(nTemp)*(1000000000.0/pow(10.0,nDigits)); + nNanoSeconds = nTemp; + sal_Int32 nDigits = nPos - nStart; + assert(nDigits >= 0); + for (; nDigits < 9; ++nDigits) + { + nNanoSeconds *= 10; + } nTemp=-1; if (sal_Unicode('S') == string[nPos]) { |