diff options
author | Milo Yip <miloyip@gmail.com> | 2021-06-11 06:49:14 +0300 |
---|---|---|
committer | Milo Yip <miloyip@gmail.com> | 2021-06-11 06:49:14 +0300 |
commit | 8c29a7b4935e5d873a5f8e0a95388db8b35a3777 (patch) | |
tree | 00d4285f7595819024e2b855eae132016787a5c3 | |
parent | 17aa824c928ea111e9b12a61e06d98335ce98f15 (diff) |
Fix Pointer::Append() crash for custom allocator on Windows
Fix #1899
-rw-r--r-- | include/rapidjson/pointer.h | 2 | ||||
-rw-r--r-- | test/unittest/pointertest.cpp | 15 |
2 files changed, 15 insertions, 2 deletions
diff --git a/include/rapidjson/pointer.h b/include/rapidjson/pointer.h index 90e5903b..96214428 100644 --- a/include/rapidjson/pointer.h +++ b/include/rapidjson/pointer.h @@ -163,7 +163,7 @@ public: GenericPointer(const Token* tokens, size_t tokenCount) : allocator_(), ownAllocator_(), nameBuffer_(), tokens_(const_cast<Token*>(tokens)), tokenCount_(tokenCount), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {} //! Copy constructor. - GenericPointer(const GenericPointer& rhs) : allocator_(rhs.allocator_), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) { + GenericPointer(const GenericPointer& rhs) : allocator_(), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) { *this = rhs; } diff --git a/test/unittest/pointertest.cpp b/test/unittest/pointertest.cpp index 43718038..50c678e1 100644 --- a/test/unittest/pointertest.cpp +++ b/test/unittest/pointertest.cpp @@ -475,7 +475,9 @@ TEST(Pointer, CopyConstructor) { EXPECT_EQ(1u, q.GetTokens()[1].length); EXPECT_STREQ("0", q.GetTokens()[1].name); EXPECT_EQ(0u, q.GetTokens()[1].index); - EXPECT_EQ(&p.GetAllocator(), &q.GetAllocator()); + + // Copied pointer needs to have its own allocator + EXPECT_NE(&p.GetAllocator(), &q.GetAllocator()); } // Static tokens @@ -1668,3 +1670,14 @@ TEST(Pointer, Issue483) { value.SetString(mystr.c_str(), static_cast<SizeType>(mystr.length()), document.GetAllocator()); myjson::Pointer(path.c_str()).Set(document, value, document.GetAllocator()); } + +TEST(Pointer, Issue1899) { + typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType; + PointerType p; + PointerType q = p.Append("foo"); + EXPECT_TRUE(PointerType("/foo") == q); + q = q.Append(1234); + EXPECT_TRUE(PointerType("/foo/1234") == q); + q = q.Append(""); + EXPECT_TRUE(PointerType("/foo/1234/") == q); +}
\ No newline at end of file |