diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2013-06-06 15:30:14 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2013-06-06 15:43:10 +0200 |
commit | 9bf6c83367cedb7be81bf67f30d2147d26c7a8c3 (patch) | |
tree | d322dc6ffad9d5ef83a93bc17ef1e2a4503fe661 /sal | |
parent | 7a62dba0ba4915e4029a3eb4d41311489d73c933 (diff) |
Revert overflow checks in O[U]String::toInt{32,64} again
...originally introduced with bd60d41176da540b01d7583cfe00637431967f39 "Handle
oveflow in O(U)String::toInt() functions." As pointed out by Noel Power, there
is existing code using toInt32(16) to read an effectively unsigned hex string
into a sal_Int32, which used to work fine with the wrap-around overflow but now
fails when toInt32 explicitly returns 0 for large values. See, e.g., use of
oox::AttributeList::getIntegerHex (indirectly calling OUString::toInt32) in
ColorScaleRule::importColor (sc/source/filter/oox/condformatbuffer.cxx).
To prevent any regressions in LO 4.1, remove the explicit checks from
toInt{32,64} again for now. (They were "merely" added as a general safety
measure, not to address some specific problem, IIRC.) On master, the approach
will rather be to introduce toUInt32 and adapt client code as necessary.
Change-Id: Id332cff18a99b8bd2dcccd7988b7aad3a9e98c4c
Diffstat (limited to 'sal')
-rw-r--r-- | sal/qa/rtl/strings/test_strings_toint.cxx | 4 | ||||
-rw-r--r-- | sal/rtl/strtmpl.cxx | 24 |
2 files changed, 0 insertions, 28 deletions
diff --git a/sal/qa/rtl/strings/test_strings_toint.cxx b/sal/qa/rtl/strings/test_strings_toint.cxx index 4a4f549e4495..102d30e060e4 100644 --- a/sal/qa/rtl/strings/test_strings_toint.cxx +++ b/sal/qa/rtl/strings/test_strings_toint.cxx @@ -27,16 +27,13 @@ private: CPPUNIT_TEST_SUITE_END(); void testToInt32Overflow() { - CPPUNIT_ASSERT_EQUAL(sal_Int32(0), T("-2147483649").toInt32()); CPPUNIT_ASSERT_EQUAL(SAL_MIN_INT32, T("-2147483648").toInt32()); CPPUNIT_ASSERT_EQUAL(SAL_MIN_INT32 + 1, T("-2147483647").toInt32()); CPPUNIT_ASSERT_EQUAL(SAL_MAX_INT32 - 1, T("2147483646").toInt32()); CPPUNIT_ASSERT_EQUAL(SAL_MAX_INT32, T("2147483647").toInt32()); - CPPUNIT_ASSERT_EQUAL(sal_Int32(0), T("2147483648").toInt32()); } void testToInt64Overflow() { - CPPUNIT_ASSERT_EQUAL(sal_Int64(0), T("-9223372036854775809").toInt64()); CPPUNIT_ASSERT_EQUAL( SAL_MIN_INT64, T("-9223372036854775808").toInt64()); CPPUNIT_ASSERT_EQUAL( @@ -44,7 +41,6 @@ private: CPPUNIT_ASSERT_EQUAL( SAL_MAX_INT64 - 1, T("9223372036854775806").toInt64()); CPPUNIT_ASSERT_EQUAL(SAL_MAX_INT64, T("9223372036854775807").toInt64()); - CPPUNIT_ASSERT_EQUAL(sal_Int64(0), T("9223372036854775808").toInt64()); } void testToUInt64Overflow() { diff --git a/sal/rtl/strtmpl.cxx b/sal/rtl/strtmpl.cxx index 78aa1f57b863..dd1effc85eb8 100644 --- a/sal/rtl/strtmpl.cxx +++ b/sal/rtl/strtmpl.cxx @@ -941,35 +941,11 @@ namespace { bNeg = sal_False; } - T nDiv; - sal_Int16 nMod; - if ( bNeg ) - { - nDiv = std::numeric_limits<T>::min() / nRadix; - nMod = std::numeric_limits<T>::min() % nRadix; - // Cater for C++03 implementations that round the quotient down - // instead of truncating towards zero as mandated by C++11: - if ( nMod > 0 ) - { - --nDiv; - nMod -= nRadix; - } - nDiv = -nDiv; - nMod = -nMod; - } - else - { - nDiv = std::numeric_limits<T>::max() / nRadix; - nMod = std::numeric_limits<T>::max() % nRadix; - } - while ( *pStr ) { nDigit = rtl_ImplGetDigit( IMPL_RTL_USTRCODE( *pStr ), nRadix ); if ( nDigit < 0 ) break; - if( ( nMod < nDigit ? nDiv-1 : nDiv ) < n ) - return 0; n *= nRadix; n += nDigit; |