From 415185de33fb07cbebf03236bf5a1db69cfb3d60 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Mon, 8 May 2017 21:18:24 +0100 Subject: coverity#1250405 Division or modulo by float zero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit another stab at this Change-Id: I893f4b4a211a85718bf51bfbdb3e8bdb1df0066c Reviewed-on: https://gerrit.libreoffice.org/37405 Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- vcl/source/outdev/map.cxx | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'vcl') diff --git a/vcl/source/outdev/map.cxx b/vcl/source/outdev/map.cxx index 619107c40978..f37116748603 100644 --- a/vcl/source/outdev/map.cxx +++ b/vcl/source/outdev/map.cxx @@ -256,48 +256,51 @@ static void ImplCalcMapResolution( const MapMode& rMapMode, } else { + auto nXNumerator = aScaleX.GetNumerator(); + auto nYNumerator = aScaleY.GetNumerator(); + assert(nXNumerator != 0 && nYNumerator != 0); rMapRes.mfOffsetX *= aScaleX.GetDenominator(); - rMapRes.mfOffsetX /= aScaleX.GetNumerator(); + rMapRes.mfOffsetX /= nXNumerator; rMapRes.mfOffsetX += aOrigin.X(); rMapRes.mfOffsetY *= aScaleY.GetDenominator(); - rMapRes.mfOffsetY /= aScaleY.GetNumerator(); + rMapRes.mfOffsetY /= nYNumerator; rMapRes.mfOffsetY += aOrigin.Y(); BigInt aX( rMapRes.mnMapOfsX ); aX *= BigInt( aScaleX.GetDenominator() ); if ( rMapRes.mnMapOfsX >= 0 ) { - if ( aScaleX.GetNumerator() >= 0 ) - aX += BigInt( aScaleX.GetNumerator()/2 ); + if (nXNumerator >= 0) + aX += BigInt(nXNumerator / 2); else - aX -= BigInt( (aScaleX.GetNumerator()+1)/2 ); + aX -= BigInt((nXNumerator + 1) / 2); } else { - if ( aScaleX.GetNumerator() >= 0 ) - aX -= BigInt( (aScaleX.GetNumerator()-1)/2 ); + if (nXNumerator >= 0 ) + aX -= BigInt((nXNumerator - 1) / 2); else - aX += BigInt( aScaleX.GetNumerator()/2 ); + aX += BigInt(nXNumerator / 2); } - aX /= BigInt( aScaleX.GetNumerator() ); + aX /= BigInt(nXNumerator); rMapRes.mnMapOfsX = (long)aX + aOrigin.X(); BigInt aY( rMapRes.mnMapOfsY ); aY *= BigInt( aScaleY.GetDenominator() ); if( rMapRes.mnMapOfsY >= 0 ) { - if ( aScaleY.GetNumerator() >= 0 ) - aY += BigInt( aScaleY.GetNumerator()/2 ); + if (nYNumerator >= 0) + aY += BigInt(nYNumerator / 2); else - aY -= BigInt( (aScaleY.GetNumerator()+1)/2 ); + aY -= BigInt((nYNumerator + 1) / 2); } else { - if ( aScaleY.GetNumerator() >= 0 ) - aY -= BigInt( (aScaleY.GetNumerator()-1)/2 ); + if (nYNumerator >= 0) + aY -= BigInt((nYNumerator - 1) / 2); else - aY += BigInt( aScaleY.GetNumerator()/2 ); + aY += BigInt(nYNumerator / 2); } - aY /= BigInt( aScaleY.GetNumerator() ); + aY /= BigInt(nYNumerator); rMapRes.mnMapOfsY = (long)aY + aOrigin.Y(); } -- cgit