Skip to content

Commit 2e9b7b1

Browse files
StilesCrisisStilesCrisis
authored andcommitted
Added assertion
Documented existing assertions in EndObject Added new assertion in EndObject to catch error condition where objects are ended with a key but no matching value.
1 parent 595b114 commit 2e9b7b1

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

include/rapidjson/writer.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,9 @@ class Writer {
221221

222222
bool EndObject(SizeType memberCount = 0) {
223223
(void)memberCount;
224-
RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level));
225-
RAPIDJSON_ASSERT(!level_stack_.template Top<Level>()->inArray);
224+
RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level)); // not inside an Object
225+
RAPIDJSON_ASSERT(!level_stack_.template Top<Level>()->inArray); // currently inside an Array, not Object
226+
RAPIDJSON_ASSERT(0 == level_stack_.template Top<Level>()->valueCount % 2); // Object has a Key without a Value
226227
level_stack_.template Pop<Level>(1);
227228
return EndValue(WriteEndObject());
228229
}

0 commit comments

Comments
 (0)