Commit a0e5e68f authored by Philipp A. Hartmann's avatar Philipp A. Hartmann

GenericDocument::Accept: deep-copy strings, if needed

Instead of always just shallowly referencing the potentially allocated
strings when calling the Handler::String function, request a copy in
case the string has been allocated from an Allocator before.

This is necessary to avoid double free()s of the string memory,
especially when using the Handler to create a deep copy of a Value.

The explicit comparison against '0' is done to suppress the warning
C4800 on MSVC, see pah/rapidjson#5.
parent 60b8c119
......@@ -579,7 +579,7 @@ int z = a[0u].GetInt(); // This works too.
case kObjectType:
handler.StartObject();
for (ConstMemberIterator m = MemberBegin(); m != MemberEnd(); ++m) {
handler.String(m->name.data_.s.str, m->name.data_.s.length, false);
handler.String(m->name.data_.s.str, m->name.data_.s.length, (m->name.flags_ & kCopyFlag) != 0);
m->value.Accept(handler);
}
handler.EndObject(data_.o.size);
......@@ -593,7 +593,7 @@ int z = a[0u].GetInt(); // This works too.
break;
case kStringType:
handler.String(data_.s.str, data_.s.length, false);
handler.String(data_.s.str, data_.s.length, (flags_ & kCopyFlag) != 0);
break;
case kNumberType:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment