From f69067fd66d898cca072ce91c2a04adc794378f0 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Thu, 30 Oct 2014 09:28:24 +0000 Subject: coverity#1244939 Division or modulo by float zero and coverity#1244938 Division or modulo by float zero Change-Id: I128b1ac10f514285152cf189af24885460c9c5ca --- .../customshapes/EnhancedCustomShapeFontWork.cxx | 36 +++++++++++++--------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'svx/source/customshapes/EnhancedCustomShapeFontWork.cxx') diff --git a/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx b/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx index b3bc74237baa..ae31f0080514 100644 --- a/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx +++ b/svx/source/customshapes/EnhancedCustomShapeFontWork.cxx @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -741,22 +742,27 @@ void FitTextOutlinesToShapeOutlines( const tools::PolyPolygon& aOutlines2d, FWDa InsertMissingOutlinePoints( rOutlinePoly, vDistances, rTextAreaBoundRect, aLocalPoly ); InsertMissingOutlinePoints( rOutlinePoly2, vDistances2, rTextAreaBoundRect, aLocalPoly ); - sal_uInt16 j, _nPointCount = aLocalPoly.GetSize(); - for ( j = 0; j < _nPointCount; j++ ) + sal_uInt16 _nPointCount = aLocalPoly.GetSize(); + if (_nPointCount) { - Point& rPoint = aLocalPoly[ j ]; - rPoint.X() -= nLeft; - rPoint.Y() -= nTop; - double fX = (double)rPoint.X() / (double)nWidth; - double fY = (double)rPoint.Y() / (double)nHeight; - - double fx1, fy1, fx2, fy2; - GetPoint( rOutlinePoly, vDistances, fX, fx1, fy1 ); - GetPoint( rOutlinePoly2, vDistances2, fX, fx2, fy2 ); - double fWidth = fx2 - fx1; - double fHeight= fy2 - fy1; - rPoint.X() = (sal_Int32)( fx1 + fWidth * fY ); - rPoint.Y() = (sal_Int32)( fy1 + fHeight* fY ); + if (!nWidth || !nHeight) + throw o3tl::divide_by_zero(); + for (sal_uInt16 j = 0; j < _nPointCount; ++j) + { + Point& rPoint = aLocalPoly[ j ]; + rPoint.X() -= nLeft; + rPoint.Y() -= nTop; + double fX = (double)rPoint.X() / (double)nWidth; + double fY = (double)rPoint.Y() / (double)nHeight; + + double fx1, fy1, fx2, fy2; + GetPoint( rOutlinePoly, vDistances, fX, fx1, fy1 ); + GetPoint( rOutlinePoly2, vDistances2, fX, fx2, fy2 ); + double fWidth = fx2 - fx1; + double fHeight= fy2 - fy1; + rPoint.X() = (sal_Int32)( fx1 + fWidth * fY ); + rPoint.Y() = (sal_Int32)( fy1 + fHeight* fY ); + } } // write back polygon -- cgit v1.2.3