Skip to content

Commit

Permalink
nanosvgrast.h: update from mainstream
Browse files Browse the repository at this point in the history
Fixes invalid memory read on single stop gradient (mainstream PR/252.)
Also removes unnecessary parentheses (mainstream PR/148)
(cherry picked from commit 9fbaa9c)
  • Loading branch information
sezero committed Dec 31, 2023
1 parent f201ed2 commit 34e2279
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/nanosvgrast.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,16 +357,16 @@ 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);
return;
}
++level;
if (level > max_level) return;

x234 = (x23+x34)*0.5f;
y234 = (y23+y34)*0.5f;
x1234 = (x123+x234)*0.5f;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 34e2279

Please sign in to comment.