Skip to content

Commit 7641af6

Browse files
authored
Merge pull request Tencent#1122 from svart-riddare/issue-1108
Suggestion for issue Tencent#1108
2 parents cdc899a + 44f2f9a commit 7641af6

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

include/rapidjson/pointer.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,12 @@ class GenericPointer {
165165
GenericPointer(const Token* tokens, size_t tokenCount) : allocator_(), ownAllocator_(), nameBuffer_(), tokens_(const_cast<Token*>(tokens)), tokenCount_(tokenCount), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {}
166166

167167
//! Copy constructor.
168-
GenericPointer(const GenericPointer& rhs, Allocator* allocator = 0) : allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {
168+
GenericPointer(const GenericPointer& rhs) : allocator_(rhs.allocator_), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {
169+
*this = rhs;
170+
}
171+
172+
//! Copy constructor.
173+
GenericPointer(const GenericPointer& rhs, Allocator* allocator) : allocator_(allocator), ownAllocator_(), nameBuffer_(), tokens_(), tokenCount_(), parseErrorOffset_(), parseErrorCode_(kPointerParseErrorNone) {
169174
*this = rhs;
170175
}
171176

test/unittest/pointertest.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,8 @@ TEST(Pointer, ConstructorWithToken) {
462462

463463
TEST(Pointer, CopyConstructor) {
464464
{
465-
Pointer p("/foo/0");
465+
CrtAllocator allocator;
466+
Pointer p("/foo/0", &allocator);
466467
Pointer q(p);
467468
EXPECT_TRUE(q.IsValid());
468469
EXPECT_EQ(2u, q.GetTokenCount());
@@ -471,6 +472,7 @@ TEST(Pointer, CopyConstructor) {
471472
EXPECT_EQ(1u, q.GetTokens()[1].length);
472473
EXPECT_STREQ("0", q.GetTokens()[1].name);
473474
EXPECT_EQ(0u, q.GetTokens()[1].index);
475+
EXPECT_EQ(&p.GetAllocator(), &q.GetAllocator());
474476
}
475477

476478
// Static tokens
@@ -489,7 +491,8 @@ TEST(Pointer, CopyConstructor) {
489491

490492
TEST(Pointer, Assignment) {
491493
{
492-
Pointer p("/foo/0");
494+
CrtAllocator allocator;
495+
Pointer p("/foo/0", &allocator);
493496
Pointer q;
494497
q = p;
495498
EXPECT_TRUE(q.IsValid());
@@ -499,6 +502,7 @@ TEST(Pointer, Assignment) {
499502
EXPECT_EQ(1u, q.GetTokens()[1].length);
500503
EXPECT_STREQ("0", q.GetTokens()[1].name);
501504
EXPECT_EQ(0u, q.GetTokens()[1].index);
505+
EXPECT_NE(&p.GetAllocator(), &q.GetAllocator());
502506
q = q;
503507
EXPECT_TRUE(q.IsValid());
504508
EXPECT_EQ(2u, q.GetTokenCount());
@@ -507,6 +511,7 @@ TEST(Pointer, Assignment) {
507511
EXPECT_EQ(1u, q.GetTokens()[1].length);
508512
EXPECT_STREQ("0", q.GetTokens()[1].name);
509513
EXPECT_EQ(0u, q.GetTokens()[1].index);
514+
EXPECT_NE(&p.GetAllocator(), &q.GetAllocator());
510515
}
511516

512517
// Static tokens

0 commit comments

Comments
 (0)