From 9b39c0b9b927a32103a2eab9c2a0d8b927f98920 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Sun, 31 Dec 2023 14:00:24 +0300
Subject: [PATCH] nanosvgrast.h: update from mainstream
Fixes invalid memory read on single stop gradient (mainstream PR/252.)
Also removes unnecessary parentheses (mainstream PR/148)
(cherry picked from commit 9fbaa9cc202ec121db454df0f74f4d11a6827558)
---
src/nanosvgrast.h | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/nanosvgrast.h b/src/nanosvgrast.h
index 9531bb4c..557037bd 100644
--- a/src/nanosvgrast.h
+++ b/src/nanosvgrast.h
@@ -357,8 +357,8 @@ static void nsvg__flattenCubicBez(NSVGrasterizer* r,
dx = x4 - x1;
dy = y4 - y1;
- d2 = nsvg__absf(((x2 - x4) * dy - (y2 - y4) * dx));
- d3 = nsvg__absf(((x3 - x4) * dy - (y3 - y4) * dx));
+ d2 = nsvg__absf((x2 - x4) * dy - (y2 - y4) * dx);
+ d3 = nsvg__absf((x3 - x4) * dy - (y3 - y4) * dx);
if ((d2 + d3)*(d2 + d3) < r->tessTol * (dx*dx + dy*dy)) {
nsvg__addPathPoint(r, x4, y4, type);
@@ -366,7 +366,7 @@ static void nsvg__flattenCubicBez(NSVGrasterizer* r,
}
++level;
if (level > max_level) return;
-
+
x234 = (x23+x34)*0.5f;
y234 = (y23+y34)*0.5f;
x1234 = (x123+x234)*0.5f;
@@ -1291,8 +1291,9 @@ static void nsvg__initPaint(NSVGcachedPaint* cache, NSVGpaint* paint, float opac
for (i = 0; i < 256; i++)
cache->colors[i] = 0;
} else if (grad->nstops == 1) {
+ unsigned int color = nsvg__applyOpacity(grad->stops[0].color, opacity);
for (i = 0; i < 256; i++)
- cache->colors[i] = nsvg__applyOpacity(grad->stops[i].color, opacity);
+ cache->colors[i] = color;
} else {
unsigned int ca, cb = 0;
float ua, ub, du, u;