Commit db0a03a4 authored by Milo Yip's avatar Milo Yip

Fix #483 by using the correct value type

parent 8ec389f1
......@@ -390,7 +390,7 @@ public:
bool exist = true;
for (const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
if (v->IsArray() && t->name[0] == '-' && t->length == 1) {
v->PushBack(Value().Move(), allocator);
v->PushBack(ValueType().Move(), allocator);
v = &((*v)[v->Size() - 1]);
exist = false;
}
......@@ -408,7 +408,7 @@ public:
if (t->index >= v->Size()) {
v->Reserve(t->index + 1, allocator);
while (t->index >= v->Size())
v->PushBack(Value().Move(), allocator);
v->PushBack(ValueType().Move(), allocator);
exist = false;
}
v = &((*v)[t->index]);
......@@ -416,7 +416,7 @@ public:
else {
typename ValueType::MemberIterator m = v->FindMember(GenericStringRef<Ch>(t->name, t->length));
if (m == v->MemberEnd()) {
v->AddMember(Value(t->name, t->length, allocator).Move(), Value().Move(), allocator);
v->AddMember(ValueType(t->name, t->length, allocator).Move(), ValueType().Move(), allocator);
v = &(--v->MemberEnd())->value; // Assumes AddMember() appends at the end
exist = false;
}
......
......@@ -1456,3 +1456,38 @@ TEST(Pointer, Ambiguity) {
EXPECT_EQ(456, Pointer("/0/1").Get(d)->GetInt());
}
}
// https://github.com/miloyip/rapidjson/issues/483
namespace myjson {
class MyAllocator
{
public:
static const bool kNeedFree = true;
void * Malloc(size_t _size) { return malloc(_size); }
void * Realloc(void *_org_p, size_t _org_size, size_t _new_size) { (void)_org_size; return realloc(_org_p, _new_size); }
static void Free(void *_p) { return free(_p); }
};
typedef rapidjson::GenericDocument<
rapidjson::UTF8<>,
rapidjson::MemoryPoolAllocator< MyAllocator >,
MyAllocator
> Document;
typedef rapidjson::GenericPointer<
::myjson::Document::ValueType,
MyAllocator
> Pointer;
typedef ::myjson::Document::ValueType Value;
}
TEST(Pointer, Issue483) {
std::string mystr, path;
myjson::Document document;
myjson::Value value(rapidjson::kStringType);
value.SetString(mystr.c_str(), mystr.length(), document.GetAllocator());
myjson::Pointer(path.c_str()).Set(document, value, document.GetAllocator());
}
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