check for end of input on every increment of the cursor
parent
f21b8c360e
commit
4b0f5cfd77
17
json11.cpp
17
json11.cpp
|
@ -373,22 +373,35 @@ struct JsonParser {
|
||||||
bool comment_found = false;
|
bool comment_found = false;
|
||||||
if (str[i] == '/') {
|
if (str[i] == '/') {
|
||||||
i++;
|
i++;
|
||||||
|
if (i == str.size())
|
||||||
|
return fail("unexpected end of input inside comment", 0);
|
||||||
if (str[i] == '/') { // inline comment
|
if (str[i] == '/') { // inline comment
|
||||||
i++;
|
i++;
|
||||||
|
if (i == str.size())
|
||||||
|
return fail("unexpected end of input inside inline comment", 0);
|
||||||
// advance until next line
|
// advance until next line
|
||||||
while (str[i] != '\n')
|
while (str[i] != '\n') {
|
||||||
i++;
|
i++;
|
||||||
|
if (i == str.size())
|
||||||
|
return fail("unexpected end of input inside inline comment", 0);
|
||||||
|
}
|
||||||
comment_found = true;
|
comment_found = true;
|
||||||
}
|
}
|
||||||
else if (str[i] == '*') { // multiline comment
|
else if (str[i] == '*') { // multiline comment
|
||||||
i++;
|
i++;
|
||||||
|
if (i == str.size())
|
||||||
|
return fail("unexpected end of input inside multi-line comment", 0);
|
||||||
// advance until closing tokens
|
// advance until closing tokens
|
||||||
while (!(str[i] == '*' && str[i+1] == '/')) {
|
while (!(str[i] == '*' && str[i+1] == '/')) {
|
||||||
|
i++;
|
||||||
if (i == str.size())
|
if (i == str.size())
|
||||||
return fail(
|
return fail(
|
||||||
"unexpected end of input inside multi-line comment", 0);
|
"unexpected end of input inside multi-line comment", 0);
|
||||||
i++;}
|
}
|
||||||
i += 2;
|
i += 2;
|
||||||
|
if (i == str.size())
|
||||||
|
return fail(
|
||||||
|
"unexpected end of input inside multi-line comment", 0);
|
||||||
comment_found = true;
|
comment_found = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue