diff --git a/ext/import-svg.cpp b/ext/import-svg.cpp index a6b5476..2b14b7e 100644 --- a/ext/import-svg.cpp +++ b/ext/import-svg.cpp @@ -17,10 +17,11 @@ namespace msdfgen { #endif -static bool readNodeType(char &output, const char *&pathDef) { +static bool readNodeType(char &output, bool &haveInput, const char *&pathDef) { int shift; char nodeType; - if (sscanf(pathDef, " %c%n", &nodeType, &shift) == 1 && nodeType != '+' && nodeType != '-' && nodeType != '.' && nodeType != ',' && (nodeType < '0' || nodeType > '9')) { + haveInput = sscanf(pathDef, " %c%n", &nodeType, &shift) == 1; + if ( haveInput && nodeType != '+' && nodeType != '-' && nodeType != '.' && nodeType != ',' && (nodeType < '0' || nodeType > '9')) { pathDef += shift; output = nodeType; return true; @@ -220,7 +221,8 @@ static Point2 handleArc(const char *&pathDef, char nodeType, Point2 prevNode, Co static bool buildFromPath(Shape &shape, const char *pathDef) { char nodeType; Point2 prevNode(0, 0); - while (readNodeType(nodeType, pathDef)) { + bool haveInput = pathDef && *pathDef; + while (haveInput && readNodeType(nodeType, haveInput, pathDef)) { Contour &contour = shape.addContour(); bool contourStart = true; @@ -228,7 +230,7 @@ static bool buildFromPath(Shape &shape, const char *pathDef) { Point2 controlPoint[2]; Point2 node; - while (*pathDef) { + while (haveInput) { switch (nodeType) { case 'M': case 'm': REQUIRE(contourStart); @@ -304,7 +306,7 @@ static bool buildFromPath(Shape &shape, const char *pathDef) { } contourStart &= nodeType == 'M' || nodeType == 'm'; prevNode = node; - readNodeType(nodeType, pathDef); + readNodeType(nodeType, haveInput, pathDef); } NEXT_CONTOUR:; }