From 85b698cbd3de7ffd3c69309d452c1bf93156b75c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Thu, 26 Oct 2017 09:20:56 +0100 Subject: [PATCH] ofz#3812 Divide-by-zero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I1a278302b995137d3e73620c003534498a59ba14 Reviewed-on: https://gerrit.libreoffice.org/43870 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- tools/source/generic/poly.cxx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/source/generic/poly.cxx b/tools/source/generic/poly.cxx index 7564e9f50125..e7b9397ab734 100644 --- a/tools/source/generic/poly.cxx +++ b/tools/source/generic/poly.cxx @@ -1687,11 +1687,14 @@ void impCorrectContinuity(basegfx::B2DPolygon& roPolygon, sal_uInt32 nIndex, Pol // calculate common direction vector, normalize const basegfx::B2DVector aDirection(aNext + aPrev); + const double fDirectionLen = aDirection.getLength(); + if (fDirectionLen == 0.0) + return; - if(PolyFlags::Smooth == nCFlag) + if (PolyFlags::Smooth == nCFlag) { // C1: apply common direction vector, preserve individual lengths - const double fInvDirectionLen(1.0 / aDirection.getLength()); + const double fInvDirectionLen(1.0 / fDirectionLen); roPolygon.setNextControlPoint(nIndex, basegfx::B2DPoint(aPoint + (aDirection * (aNext.getLength() * fInvDirectionLen)))); roPolygon.setPrevControlPoint(nIndex, basegfx::B2DPoint(aPoint - (aDirection * (aPrev.getLength() * fInvDirectionLen)))); } @@ -1699,7 +1702,7 @@ void impCorrectContinuity(basegfx::B2DPolygon& roPolygon, sal_uInt32 nIndex, Pol { // C2: get mediated length. Taking half of the unnormalized direction would be // an approximation, but not correct. - const double fMedLength((aNext.getLength() + aPrev.getLength()) * (0.5 / aDirection.getLength())); + const double fMedLength((aNext.getLength() + aPrev.getLength()) * (0.5 / fDirectionLen)); const basegfx::B2DVector aScaledDirection(aDirection * fMedLength); // Bring Direction to correct length and apply