From 4b58c5a5de3b0e244f30f9da309ee1b8d63db5d6 Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Fri, 23 Oct 2020 01:32:52 +0200 Subject: [PATCH] common shape: handling dash patterns < 1 For the dash pattern values (both, length and gap) < 1 the program crashed. curLen - variable type changed from int to float. --- src/lib/sw_engine/tvgSwCommon.h | 2 +- src/lib/sw_engine/tvgSwShape.cpp | 3 +-- src/lib/tvgShape.cpp | 4 ++++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib/sw_engine/tvgSwCommon.h b/src/lib/sw_engine/tvgSwCommon.h index 8e5a1cba..ce54180d 100644 --- a/src/lib/sw_engine/tvgSwCommon.h +++ b/src/lib/sw_engine/tvgSwCommon.h @@ -165,7 +165,7 @@ struct SwStroke struct SwDashStroke { SwOutline* outline; - int32_t curLen; + float curLen; int32_t curIdx; Point ptStart; Point ptCur; diff --git a/src/lib/sw_engine/tvgSwShape.cpp b/src/lib/sw_engine/tvgSwShape.cpp index d4cf9c26..cb2d90e6 100644 --- a/src/lib/sw_engine/tvgSwShape.cpp +++ b/src/lib/sw_engine/tvgSwShape.cpp @@ -113,7 +113,6 @@ static void _outlineMoveTo(SwOutline& outline, const Point* to, const Matrix* tr _growOutlinePoint(outline, 1); outline.pts[outline.ptsCnt] = _transform(to, transform); - outline.types[outline.ptsCnt] = SW_CURVE_TYPE_POINT; if (outline.ptsCnt > 0) { @@ -285,7 +284,7 @@ static void _dashCubicTo(SwDashStroke& dash, const Point* ctrl1, const Point* ct _growOutlinePoint(*dash.outline, dash.outline->ptsCnt >> 1); _growOutlineContour(*dash.outline, dash.outline->cntrsCnt >> 1); - Bezier cur = { dash.ptCur, *ctrl1, *ctrl2, *to}; + Bezier cur = {dash.ptCur, *ctrl1, *ctrl2, *to}; auto len = bezLength(cur); if (len < dash.curLen) { diff --git a/src/lib/tvgShape.cpp b/src/lib/tvgShape.cpp index 7cd64768..2bf6c535 100644 --- a/src/lib/tvgShape.cpp +++ b/src/lib/tvgShape.cpp @@ -339,6 +339,9 @@ Result Shape::stroke(const float* dashPattern, uint32_t cnt) noexcept { if (cnt < 2 || !dashPattern) return Result::InvalidArguments; + for (uint32_t i = 0; i < cnt; i++) + if (dashPattern[i] < FLT_EPSILON) return Result::InvalidArguments; + if (!pImpl->strokeDash(dashPattern, cnt)) return Result::FailedAllocation; return Result::Success; @@ -350,6 +353,7 @@ uint32_t Shape::strokeDash(const float** dashPattern) const noexcept if (!pImpl->stroke) return 0; if (dashPattern) *dashPattern = pImpl->stroke->dashPattern; + return pImpl->stroke->dashCnt; }