common shape: handling dash patterns < 1
authorMira Grudzinska <m.grudzinska@samsung.com>
Thu, 22 Oct 2020 23:32:52 +0000 (01:32 +0200)
committerHermet Park <chuneon.park@samsung.com>
Fri, 23 Oct 2020 09:02:42 +0000 (18:02 +0900)
For the dash pattern values (both, length and gap) < 1 the program crashed.
curLen - variable type changed from int to float.

Change-Id: I9a50f1d247c210de7e5017b652554d94f00eb875

src/lib/sw_engine/tvgSwCommon.h
src/lib/sw_engine/tvgSwShape.cpp
src/lib/tvgShape.cpp

index 8e5a1cb..ce54180 100644 (file)
@@ -165,7 +165,7 @@ struct SwStroke
 struct SwDashStroke
 {
     SwOutline* outline;
-    int32_t curLen;
+    float curLen;
     int32_t curIdx;
     Point ptStart;
     Point ptCur;
index d4cf9c2..cb2d90e 100644 (file)
@@ -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) {
index 7cd6476..2bf6c53 100644 (file)
@@ -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;
 }