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

Commit

Permalink
Use value stack for checking maximum depth.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
canatella committed Dec 29, 2016
1 parent ff61ca1 commit eb177d0
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions json11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,8 +717,8 @@ struct JsonParserPriv final {
*
* Parse a JSON object.
*/
void parse_json(int depth) {
if (depth > max_depth) {
void parse_json() {
if (values.size() > max_depth) {
return fail("exceeded maximum nesting depth");
}

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

parse_json(depth + 1);
parse_json();
if (need_data)
return;

Expand Down Expand Up @@ -813,7 +813,7 @@ struct JsonParserPriv final {
return;

i--;
parse_json(depth + 1);
parse_json();
if (need_data)
return;

Expand Down Expand Up @@ -860,7 +860,7 @@ JsonParser::~JsonParser() {
void JsonParser::consume(const std::string &in) {
parser->str = in;
parser->eof = true;
parser->parse_json(0);
parser->parse_json();
}

Json JsonParser::json() const {
Expand All @@ -870,7 +870,7 @@ Json JsonParser::json() const {
Json Json::parse(const string &in, string &err, JsonParse strategy) {
JsonParserPriv parser { in, err, strategy };
parser.eof = true;
parser.parse_json(0);
parser.parse_json();

// Check for any trailing garbage
parser.consume_garbage();
Expand Down Expand Up @@ -902,7 +902,7 @@ vector<Json> Json::parse_multi(const string &in,
parser_stop_pos = 0;
vector<Json> json_vec;
while (parser.i != in.size() && !parser.failed && !parser.need_data) {
parser.parse_json(0);
parser.parse_json();
if (parser.need_data) {
parser.failed = true;
parser.values.push(Json());
Expand Down

0 comments on commit eb177d0

Please sign in to comment.