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.
This commit is contained in:
Philipp A. Hartmann 2014-02-28 12:09:24 +01:00
parent 60b8c11909
commit a0e5e68fdb

View File

@ -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: