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 Jul 20, 2018
1 parent 8e75cda commit a573824
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 @@ -837,6 +837,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 @@ -1002,7 +1003,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 @@ -1015,7 +1019,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 @@ -2744,7 +2751,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 @@ -2753,7 +2762,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 a573824

Please sign in to comment.