Skip to content

Commit

Permalink
Merge pull request Tencent#1969 from MalcolmTyrrell/MalcolmTyrrell/sa…
Browse files Browse the repository at this point in the history
…nitizeSchemaCode

Sanitize the code in schema.h
  • Loading branch information
miloyip authored Mar 9, 2022
2 parents 0d78b1c + 53602ec commit 8261c1d
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions include/rapidjson/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -2349,7 +2349,8 @@ RAPIDJSON_MULTILINEMACRO_END
if (!valid_) return false; \
if ((!BeginValue() && !GetContinueOnErrors()) || (!CurrentSchema().method arg1 && !GetContinueOnErrors())) {\
RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_();\
return valid_ = false;\
valid_ = false;\
return valid_;\
}

#define RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(method, arg2)\
Expand Down Expand Up @@ -2388,34 +2389,46 @@ RAPIDJSON_MULTILINEMACRO_END
bool StartObject() {
RAPIDJSON_SCHEMA_HANDLE_BEGIN_(StartObject, (CurrentContext()));
RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(StartObject, ());
return valid_ = !outputHandler_ || outputHandler_->StartObject();
valid_ = !outputHandler_ || outputHandler_->StartObject();
return valid_;
}

bool Key(const Ch* str, SizeType len, bool copy) {
if (!valid_) return false;
AppendToken(str, len);
if (!CurrentSchema().Key(CurrentContext(), str, len, copy) && !GetContinueOnErrors()) return valid_ = false;
if (!CurrentSchema().Key(CurrentContext(), str, len, copy) && !GetContinueOnErrors()) {
valid_ = false;
return valid_;
}
RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(Key, (str, len, copy));
return valid_ = !outputHandler_ || outputHandler_->Key(str, len, copy);
valid_ = !outputHandler_ || outputHandler_->Key(str, len, copy);
return valid_;
}

bool EndObject(SizeType memberCount) {
if (!valid_) return false;
RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(EndObject, (memberCount));
if (!CurrentSchema().EndObject(CurrentContext(), memberCount) && !GetContinueOnErrors()) return valid_ = false;
if (!CurrentSchema().EndObject(CurrentContext(), memberCount) && !GetContinueOnErrors()) {
valid_ = false;
return valid_;
}
RAPIDJSON_SCHEMA_HANDLE_END_(EndObject, (memberCount));
}

bool StartArray() {
RAPIDJSON_SCHEMA_HANDLE_BEGIN_(StartArray, (CurrentContext()));
RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(StartArray, ());
return valid_ = !outputHandler_ || outputHandler_->StartArray();
valid_ = !outputHandler_ || outputHandler_->StartArray();
return valid_;
}

bool EndArray(SizeType elementCount) {
if (!valid_) return false;
RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(EndArray, (elementCount));
if (!CurrentSchema().EndArray(CurrentContext(), elementCount) && !GetContinueOnErrors()) return valid_ = false;
if (!CurrentSchema().EndArray(CurrentContext(), elementCount) && !GetContinueOnErrors()) {
valid_ = false;
return valid_;
}
RAPIDJSON_SCHEMA_HANDLE_END_(EndArray, (elementCount));
}

Expand Down

0 comments on commit 8261c1d

Please sign in to comment.