From b7a906a0b6acff31723df6d2773587da3c9645c5 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 27 Jun 2020 13:35:33 +0100 Subject: [PATCH] sfzero: fix crash on multi-line c-style comments Fixes #1183 Signed-off-by: falkTX --- source/modules/sfzero/sfzero/SFZReader.cpp | 41 +++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/source/modules/sfzero/sfzero/SFZReader.cpp b/source/modules/sfzero/sfzero/SFZReader.cpp index b617e7074..ac0b7d0df 100644 --- a/source/modules/sfzero/sfzero/SFZReader.cpp +++ b/source/modules/sfzero/sfzero/SFZReader.cpp @@ -41,6 +41,7 @@ void Reader::read(const char *text, unsigned int length) Region curGroup; Region curRegion; Region *buildingRegion = nullptr; + bool inComment = false; bool inControl = false; bool inGroup = false; water::String defaultPath; @@ -65,15 +66,31 @@ void Reader::read(const char *text, unsigned int length) // Check if it's a comment line. if (c == '/') { - // Skip to end of line. - while (p < end) + // Skip to end of line or c-style comment. + do { c = *++p; + if (c == '*') + { + inComment = true; + continue; + } + if (inComment) + { + if (c != '*') + continue; + c = *++p; + if (c != '/') + continue; + inComment = false; + } if ((c == '\n') || (c == '\r')) { break; } } + while (p < end); + inComment = false; p = handleLineEnd(p); continue; } @@ -164,16 +181,32 @@ void Reader::read(const char *text, unsigned int length) // Comment. else if (c == '/') { - // Skip to end of line. - while (p < end) + // Skip to end of line or c-style comment. + do { c = *p; + if (c == '*') + { + inComment = true; + continue; + } + if (inComment) + { + if (c != '*') + continue; + c = *++p; + if (c != '/') + continue; + inComment = false; + } if ((c == '\r') || (c == '\n')) { break; } p += 1; } + while (p < end); + inComment = false; } // Parameter. else