Avoid calling qsort() when r->nedges == 0

In some unusual cases, r->nedges == 0 and r->edges == NULL.
At least glibc declares the array pointer for qsort() to be non-NULL,
causing UBSan (-fsanitize=nonnull-attribute) to complain.
master
Christopher Chavez 2022-05-07 06:38:26 -05:00
parent 03042a6297
commit 6c8ee8211a
1 changed files with 4 additions and 2 deletions

View File

@ -1406,7 +1406,8 @@ void nsvgRasterize(NSVGrasterizer* r,
}
// Rasterize edges
qsort(r->edges, r->nedges, sizeof(NSVGedge), nsvg__cmpEdge);
if (r->nedges != 0)
qsort(r->edges, r->nedges, sizeof(NSVGedge), nsvg__cmpEdge);
// now, traverse the scanlines and find the intersections on each scanline, use non-zero rule
nsvg__initPaint(&cache, &shape->fill, shape->opacity);
@ -1432,7 +1433,8 @@ void nsvgRasterize(NSVGrasterizer* r,
}
// Rasterize edges
qsort(r->edges, r->nedges, sizeof(NSVGedge), nsvg__cmpEdge);
if (r->nedges != 0)
qsort(r->edges, r->nedges, sizeof(NSVGedge), nsvg__cmpEdge);
// now, traverse the scanlines and find the intersections on each scanline, use non-zero rule
nsvg__initPaint(&cache, &shape->stroke, shape->opacity);