Browse Source

sfzero: fix crash on multi-line c-style comments

Fixes #1183

Signed-off-by: falkTX <falktx@falktx.com>
tags/v2.2.0-RC1
falkTX 4 years ago
parent
commit
b7a906a0b6
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
1 changed files with 37 additions and 4 deletions
  1. +37
    -4
      source/modules/sfzero/sfzero/SFZReader.cpp

+ 37
- 4
source/modules/sfzero/sfzero/SFZReader.cpp View File

@@ -41,6 +41,7 @@ void Reader::read(const char *text, unsigned int length)
Region curGroup; Region curGroup;
Region curRegion; Region curRegion;
Region *buildingRegion = nullptr; Region *buildingRegion = nullptr;
bool inComment = false;
bool inControl = false; bool inControl = false;
bool inGroup = false; bool inGroup = false;
water::String defaultPath; water::String defaultPath;
@@ -65,15 +66,31 @@ void Reader::read(const char *text, unsigned int length)
// Check if it's a comment line. // Check if it's a comment line.
if (c == '/') if (c == '/')
{ {
// Skip to end of line.
while (p < end)
// Skip to end of line or c-style comment.
do
{ {
c = *++p; c = *++p;
if (c == '*')
{
inComment = true;
continue;
}
if (inComment)
{
if (c != '*')
continue;
c = *++p;
if (c != '/')
continue;
inComment = false;
}
if ((c == '\n') || (c == '\r')) if ((c == '\n') || (c == '\r'))
{ {
break; break;
} }
} }
while (p < end);
inComment = false;
p = handleLineEnd(p); p = handleLineEnd(p);
continue; continue;
} }
@@ -164,16 +181,32 @@ void Reader::read(const char *text, unsigned int length)
// Comment. // Comment.
else if (c == '/') else if (c == '/')
{ {
// Skip to end of line.
while (p < end)
// Skip to end of line or c-style comment.
do
{ {
c = *p; c = *p;
if (c == '*')
{
inComment = true;
continue;
}
if (inComment)
{
if (c != '*')
continue;
c = *++p;
if (c != '/')
continue;
inComment = false;
}
if ((c == '\r') || (c == '\n')) if ((c == '\r') || (c == '\n'))
{ {
break; break;
} }
p += 1; p += 1;
} }
while (p < end);
inComment = false;
} }
// Parameter. // Parameter.
else else


Loading…
Cancel
Save