From 71da7445e50eadfce261fcd2f82d16cbaa017041 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Mon, 8 Jan 2018 09:58:31 +0000 Subject: ofz#5000 Integer-overflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I74871848ddddafd1a89ddb3eee4a307cc5d7c16b Reviewed-on: https://gerrit.libreoffice.org/47573 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- tools/source/generic/bigint.cxx | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'tools') diff --git a/tools/source/generic/bigint.cxx b/tools/source/generic/bigint.cxx index cda2be1843d7..6fa9a2c472f0 100644 --- a/tools/source/generic/bigint.cxx +++ b/tools/source/generic/bigint.cxx @@ -330,21 +330,21 @@ void BigInt::DivLong( const BigInt& rB, BigInt& rErg ) const for (j = aTmpA.nLen - 1; j >= nLenB; j--) { // guess divisor - sal_Int32 nTmp = ( (sal_Int32)aTmpA.nNum[j] << 16 ) + aTmpA.nNum[j - 1]; + sal_uInt32 nTmp = ( (sal_uInt32)aTmpA.nNum[j] << 16 ) + aTmpA.nNum[j - 1]; if (aTmpA.nNum[j] == aTmpB.nNum[nLenB1]) nQ = 0xFFFF; else - nQ = (sal_uInt16)(((sal_uInt32)nTmp) / aTmpB.nNum[nLenB1]); + nQ = (sal_uInt16)(nTmp / aTmpB.nNum[nLenB1]); if ( ((sal_uInt32)aTmpB.nNum[nLenB1 - 1] * nQ) > - ((((sal_uInt32)nTmp) - (sal_uInt32)aTmpB.nNum[nLenB1] * nQ) << 16) + aTmpA.nNum[j - 2]) + ((nTmp - (sal_uInt32)aTmpB.nNum[nLenB1] * nQ) << 16) + aTmpA.nNum[j - 2]) nQ--; // Start division nK = 0; for (i = 0; i < nLenB; i++) { - nTmp = (sal_Int32)aTmpA.nNum[j - nLenB + i] - - ((sal_Int32)aTmpB.nNum[i] * nQ) + nTmp = (sal_uInt32)aTmpA.nNum[j - nLenB + i] + - ((sal_uInt32)aTmpB.nNum[i] * nQ) - nK; aTmpA.nNum[j - nLenB + i] = (sal_uInt16)nTmp; nK = (sal_uInt16) (nTmp >> 16); @@ -397,21 +397,21 @@ void BigInt::ModLong( const BigInt& rB, BigInt& rErg ) const for (j = aTmpA.nLen - 1; j >= nLenB; j--) { // Guess divisor - sal_Int32 nTmp = ( (sal_Int32)aTmpA.nNum[j] << 16 ) + aTmpA.nNum[j - 1]; + sal_uInt32 nTmp = ( (sal_uInt32)aTmpA.nNum[j] << 16 ) + aTmpA.nNum[j - 1]; if (aTmpA.nNum[j] == aTmpB.nNum[nLenB1]) nQ = 0xFFFF; else - nQ = (sal_uInt16)(((sal_uInt32)nTmp) / aTmpB.nNum[nLenB1]); + nQ = (sal_uInt16)(nTmp / aTmpB.nNum[nLenB1]); if ( ((sal_uInt32)aTmpB.nNum[nLenB1 - 1] * nQ) > - ((((sal_uInt32)nTmp) - aTmpB.nNum[nLenB1] * nQ) << 16) + aTmpA.nNum[j - 2]) + ((nTmp - aTmpB.nNum[nLenB1] * nQ) << 16) + aTmpA.nNum[j - 2]) nQ--; // Start division nK = 0; for (i = 0; i < nLenB; i++) { - nTmp = (sal_Int32)aTmpA.nNum[j - nLenB + i] - - ((sal_Int32)aTmpB.nNum[i] * nQ) + nTmp = (sal_uInt32)aTmpA.nNum[j - nLenB + i] + - ((sal_uInt32)aTmpB.nNum[i] * nQ) - nK; aTmpA.nNum[j - nLenB + i] = (sal_uInt16)nTmp; nK = (sal_uInt16) (nTmp >> 16); -- cgit