Skip to content

Commit

Permalink
new fallbacks for gradientLink == NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
poke1024 committed Mar 15, 2019
1 parent ab07e18 commit 02072e0
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/nanosvg.h
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ static NSVGgradient* nsvg__createGradient(NSVGparser* p, NSVGshape* shape, NSVGg
float ox, oy, sw, sh, sl;
int nstops = 0;

if (link == NULL) return NULL;
data = nsvg__findGradientData(p, link->id);
if (data == NULL) return NULL;

Expand Down Expand Up @@ -1009,7 +1010,10 @@ static void nsvg__addShape(NSVGparser* p)
} else if (attr->hasFill == 2) {
shape->fill.type = NSVG_PAINT_GRADIENT_LINK;
shape->fill.gradientLink = nsvg__createGradientLink(attr->fillGradient, attr->xform);
if (shape->fill.gradientLink == NULL) goto error;
if (shape->fill.gradientLink == NULL) {
shape->fill.type = NSVG_PAINT_NONE;
goto error;
}
}

// Set stroke
Expand All @@ -1022,7 +1026,10 @@ static void nsvg__addShape(NSVGparser* p)
} else if (attr->hasStroke == 2) {
shape->stroke.type = NSVG_PAINT_GRADIENT_LINK;
shape->stroke.gradientLink = nsvg__createGradientLink(attr->strokeGradient, attr->xform);
if (shape->stroke.gradientLink == NULL) goto error;
if (shape->stroke.gradientLink == NULL) {
shape->stroke.type = NSVG_PAINT_NONE;
goto error;
}
}

// Set flags
Expand Down Expand Up @@ -2764,7 +2771,9 @@ static void nsvg__assignGradients(NSVGparser* p)
NSVGgradientLink* link = shape->fill.gradientLink;
shape->fill.gradient = nsvg__createGradient(
p, shape, link, &shape->fill.type);
free(link);
if (link != NULL) {
free(link);
}
if (shape->fill.gradient == NULL) {
shape->fill.type = NSVG_PAINT_NONE;
}
Expand All @@ -2773,7 +2782,9 @@ static void nsvg__assignGradients(NSVGparser* p)
NSVGgradientLink* link = shape->stroke.gradientLink;
shape->stroke.gradient = nsvg__createGradient(
p, shape, link, &shape->stroke.type);
free(link);
if (link != NULL) {
free(link);
}
if (shape->stroke.gradient == NULL) {
shape->stroke.type = NSVG_PAINT_NONE;
}
Expand Down

0 comments on commit 02072e0

Please sign in to comment.