From fe14c0386c361559822a3e447e7f8baedce33556 Mon Sep 17 00:00:00 2001 From: djack1010 Date: Sat, 22 Apr 2017 23:45:24 +0200 Subject: [PATCH] Ignore malformed attributes in XML --- src/nanosvg.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/nanosvg.h b/src/nanosvg.h index 1ad8a9a..70175b3 100644 --- a/src/nanosvg.h +++ b/src/nanosvg.h @@ -279,6 +279,9 @@ static void nsvg__parseElement(char* s, // Get attribs while (!end && *s && nattr < NSVG_XML_MAX_ATTRIBS-3) { + char* attr_ptr = NULL; + char* value_ptr = NULL; + // Skip white space before the attrib name while (*s && nsvg__isspace(*s)) s++; if (!*s) break; @@ -286,7 +289,7 @@ static void nsvg__parseElement(char* s, end = 1; break; } - attr[nattr++] = s; + attr_ptr = s; // Find end of the attrib name. while (*s && !nsvg__isspace(*s) && *s != '=') s++; if (*s) { *s++ = '\0'; } @@ -296,9 +299,15 @@ static void nsvg__parseElement(char* s, quote = *s; s++; // Store value and find the end of it. - attr[nattr++] = s; + value_ptr = s; while (*s && *s != quote) s++; if (*s) { *s++ = '\0'; } + + // Store only well formed attributes + if (attr_ptr && value_ptr) { + attr[nattr++] = attr_ptr; + attr[nattr++] = value_ptr; + } } // List terminator