Skip to content
This repository was archived by the owner on Mar 26, 2020. It is now read-only.

Commit eb177d0

Browse files
committed
Use value stack for checking maximum depth.
As we now have an explicit stack, we don't need the depth variable argument to count the recursion levels. We can simply use the value stack size instead.
1 parent ff61ca1 commit eb177d0

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

json11.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,8 @@ struct JsonParserPriv final {
717717
*
718718
* Parse a JSON object.
719719
*/
720-
void parse_json(int depth) {
721-
if (depth > max_depth) {
720+
void parse_json() {
721+
if (values.size() > max_depth) {
722722
return fail("exceeded maximum nesting depth");
723723
}
724724

@@ -773,7 +773,7 @@ struct JsonParserPriv final {
773773
if (ch != ':')
774774
return fail("expected ':' in object, got " + esc(ch));
775775

776-
parse_json(depth + 1);
776+
parse_json();
777777
if (need_data)
778778
return;
779779

@@ -813,7 +813,7 @@ struct JsonParserPriv final {
813813
return;
814814

815815
i--;
816-
parse_json(depth + 1);
816+
parse_json();
817817
if (need_data)
818818
return;
819819

@@ -860,7 +860,7 @@ JsonParser::~JsonParser() {
860860
void JsonParser::consume(const std::string &in) {
861861
parser->str = in;
862862
parser->eof = true;
863-
parser->parse_json(0);
863+
parser->parse_json();
864864
}
865865

866866
Json JsonParser::json() const {
@@ -870,7 +870,7 @@ Json JsonParser::json() const {
870870
Json Json::parse(const string &in, string &err, JsonParse strategy) {
871871
JsonParserPriv parser { in, err, strategy };
872872
parser.eof = true;
873-
parser.parse_json(0);
873+
parser.parse_json();
874874

875875
// Check for any trailing garbage
876876
parser.consume_garbage();
@@ -902,7 +902,7 @@ vector<Json> Json::parse_multi(const string &in,
902902
parser_stop_pos = 0;
903903
vector<Json> json_vec;
904904
while (parser.i != in.size() && !parser.failed && !parser.need_data) {
905-
parser.parse_json(0);
905+
parser.parse_json();
906906
if (parser.need_data) {
907907
parser.failed = true;
908908
parser.values.push(Json());

0 commit comments

Comments
 (0)