Commit 4ee17e67 authored by miloyip@gmail.com's avatar miloyip@gmail.com

Fixed Issue 38: Segmentation fault with CrtAllocator

git-svn-id: https://rapidjson.googlecode.com/svn/trunk@80 c5894555-1306-4e8d-425f-1f6f381ee07c
parent 94d05da2
......@@ -269,8 +269,8 @@ public:
o.members = (Member*)allocator.Realloc(o.members, oldCapacity * sizeof(Member), o.capacity * sizeof(Member));
}
}
o.members[o.size].name = name;
o.members[o.size].value = value;
o.members[o.size].name.RawAssign(name);
o.members[o.size].value.RawAssign(value);
o.size++;
return *this;
}
......@@ -396,7 +396,7 @@ int z = a[0u].GetInt(); // This works too.
RAPIDJSON_ASSERT(IsArray());
if (data_.a.size >= data_.a.capacity)
Reserve(data_.a.capacity == 0 ? kDefaultArrayCapacity : data_.a.capacity * 2, allocator);
data_.a.elements[data_.a.size++] = value;
data_.a.elements[data_.a.size++].RawAssign(value);
return *this;
}
......
......@@ -591,3 +591,15 @@ TEST(Value, RemoveLastElement) {
objVal.RemoveMember("var3"); // Assertion here in r61
EXPECT_FALSE(objVal.HasMember("var3"));
}
// Issue 38: Segmentation fault with CrtAllocator
TEST(Document, CrtAllocator) {
typedef GenericValue<UTF8<>, CrtAllocator> V;
V::AllocatorType allocator;
V o(kObjectType);
o.AddMember("x", 1, allocator); // Should not call destructor on uninitialized name/value of newly allocated members.
V a(kArrayType);
a.PushBack(1, allocator); // Should not call destructor on uninitialized Value of newly allocated elements.
}
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