[Libreoffice-commits] core.git: vcl/source

Caolán McNamara caolanm at redhat.com
Tue May 9 07:38:54 UTC 2017


 vcl/source/outdev/map.cxx |   35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)

New commits:
commit 415185de33fb07cbebf03236bf5a1db69cfb3d60
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Mon May 8 21:18:24 2017 +0100

    coverity#1250405 Division or modulo by float zero
    
    another stab at this
    
    Change-Id: I893f4b4a211a85718bf51bfbdb3e8bdb1df0066c
    Reviewed-on: https://gerrit.libreoffice.org/37405
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

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();
     }
 


More information about the Libreoffice-commits mailing list