Skip to content

Commit

Permalink
Critical fix - parser skipValue sometimes consumed one character too …
Browse files Browse the repository at this point in the history
…many
  • Loading branch information
Chlumsky committed Jan 18, 2023
1 parent 4024d81 commit 4b9cc84
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ target_compile_features(json-cpp-gen PUBLIC cxx_std_11)
if (MSVC)
target_compile_definitions(json-cpp-gen PUBLIC _CRT_SECURE_NO_WARNINGS)
endif()

source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${JSON_CPP_GEN_HEADERS} ${JSON_CPP_GEN_SOURCES})
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT json-cpp-gen)
10 changes: 5 additions & 5 deletions generated/ConfigurationParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ void ConfigurationParser::skipWhitespace() {
}

void ConfigurationParser::skipValue() {
int openBrackets = 1;
skipWhitespace();
switch (*cur) {
case '\0':
Expand All @@ -60,22 +59,23 @@ void ConfigurationParser::skipValue() {
++cur;
return;
case '[': case '{':
while (openBrackets) {
switch (*++cur) {
++cur;
for (int openBrackets = 1; openBrackets;) {
switch (*cur) {
case '\0':
throw ErrorType::UNEXPECTED_END_OF_FILE;
case '"':
skipValue();
break;
continue;
case '[': case '{':
++openBrackets;
break;
case ']': case '}':
--openBrackets;
break;
}
++cur;
}
++cur;
return;
default:
if (isAlphanumeric(*cur) || *cur == '-' || *cur == '.') {
Expand Down
20 changes: 10 additions & 10 deletions src/ParserGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ void $::skipWhitespace() {
}
$::ErrorType $::skipValue() {
int openBrackets = 1;
skipWhitespace();
switch (*cur) {
case '\0':
Expand All @@ -29,23 +28,24 @@ void $::skipWhitespace() {
++cur;
return ErrorType::OK;
case '[': case '{':
while (openBrackets) {
switch (*++cur) {
++cur;
for (int openBrackets = 1; openBrackets;) {
switch (*cur) {
case '\0':
return ErrorType::UNEXPECTED_END_OF_FILE;
case '"':
if (ErrorType error = skipValue())
return error;
break;
continue;
case '[': case '{':
++openBrackets;
break;
case ']': case '}':
--openBrackets;
break;
}
++cur;
}
++cur;
return ErrorType::OK;
default:
if (isAlphanumeric(*cur) || *cur == '-' || *cur == '.') {
Expand Down Expand Up @@ -129,7 +129,6 @@ void $::skipWhitespace() {
}
void $::skipValue() {
int openBrackets = 1;
skipWhitespace();
switch (*cur) {
case '\0':
Expand All @@ -142,22 +141,23 @@ void $::skipValue() {
++cur;
return;
case '[': case '{':
while (openBrackets) {
switch (*++cur) {
++cur;
for (int openBrackets = 1; openBrackets;) {
switch (*cur) {
case '\0':
throw ErrorType::UNEXPECTED_END_OF_FILE;
case '"':
skipValue();
break;
continue;
case '[': case '{':
++openBrackets;
break;
case ']': case '}':
--openBrackets;
break;
}
++cur;
}
++cur;
return;
default:
if (isAlphanumeric(*cur) || *cur == '-' || *cur == '.') {
Expand Down

0 comments on commit 4b9cc84

Please sign in to comment.