summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
Diffstat (limited to 'sal')
-rw-r--r--sal/rtl/strtmpl.cxx24
1 files changed, 22 insertions, 2 deletions
diff --git a/sal/rtl/strtmpl.cxx b/sal/rtl/strtmpl.cxx
index 6859af15b31e..455a6aebd540 100644
--- a/sal/rtl/strtmpl.cxx
+++ b/sal/rtl/strtmpl.cxx
@@ -941,8 +941,28 @@ namespace {
bNeg = sal_False;
}
- const T nDiv = bNeg ? -(std::numeric_limits<T>::min()/nRadix) : (std::numeric_limits<T>::max()/nRadix);
- const sal_Int16 nMod = bNeg ? -(std::numeric_limits<T>::min()%nRadix) : (std::numeric_limits<T>::max()%nRadix);
+ 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 );