Skip to content

Commit 8c29a7b

Browse files
committed
Fix Pointer::Append() crash for custom allocator on Windows
Fix Tencent#1899
1 parent 17aa824 commit 8c29a7b

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

include/rapidjson/pointer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class GenericPointer {
163163
GenericPointer(const Token* tokens, size_t tokenCount) : allocator_(), ownAllocator_(), nameBuffer_(), tokens_(const_cast<Token*>(tokens)), tokenCount_(tokenCount), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {}
164164

165165
//! Copy constructor.
166-
GenericPointer(const GenericPointer& rhs) : allocator_(rhs.allocator_), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {
166+
GenericPointer(const GenericPointer& rhs) : allocator_(), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {
167167
*this = rhs;
168168
}
169169

test/unittest/pointertest.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,9 @@ TEST(Pointer, CopyConstructor) {
475475
EXPECT_EQ(1u, q.GetTokens()[1].length);
476476
EXPECT_STREQ("0", q.GetTokens()[1].name);
477477
EXPECT_EQ(0u, q.GetTokens()[1].index);
478-
EXPECT_EQ(&p.GetAllocator(), &q.GetAllocator());
478+
479+
// Copied pointer needs to have its own allocator
480+
EXPECT_NE(&p.GetAllocator(), &q.GetAllocator());
479481
}
480482

481483
// Static tokens
@@ -1668,3 +1670,14 @@ TEST(Pointer, Issue483) {
16681670
value.SetString(mystr.c_str(), static_cast<SizeType>(mystr.length()), document.GetAllocator());
16691671
myjson::Pointer(path.c_str()).Set(document, value, document.GetAllocator());
16701672
}
1673+
1674+
TEST(Pointer, Issue1899) {
1675+
typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
1676+
PointerType p;
1677+
PointerType q = p.Append("foo");
1678+
EXPECT_TRUE(PointerType("/foo") == q);
1679+
q = q.Append(1234);
1680+
EXPECT_TRUE(PointerType("/foo/1234") == q);
1681+
q = q.Append("");
1682+
EXPECT_TRUE(PointerType("/foo/1234/") == q);
1683+
}

0 commit comments

Comments
 (0)