diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index 4a184c0a9..8b58c5aa6 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -243,12 +243,16 @@ class GenericReader { case '[': ParseArray(is, handler); break; default: RAPIDJSON_PARSE_ERROR_NORETURN("Expect either an object or array at root", is.Tell()); } + if (HasParseError()) + goto out; + SkipWhitespace(is); if (is.Peek() != '\0') RAPIDJSON_PARSE_ERROR_NORETURN("Nothing should follow the root object or array.", is.Tell()); } + out: stack_.Clear(); return !HasParseError(); } @@ -414,6 +418,8 @@ class GenericReader { if (parseFlags & kParseInsituFlag) { Ch *head = s.PutBegin(); ParseStringToStream(s, s); + if (HasParseError()) + return; size_t length = s.PutEnd(head) - 1; RAPIDJSON_ASSERT(length <= 0xFFFFFFFF); handler.String((typename TargetEncoding::Ch*)head, SizeType(length), false); @@ -421,6 +427,8 @@ class GenericReader { else { StackStream stackStream(stack_); ParseStringToStream(s, stackStream); + if (HasParseError()) + return; handler.String(stack_.template Pop(stackStream.length_), stackStream.length_ - 1, true); } is = s; // Restore is