Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/miloyip/rapidjson.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormiloyip <miloyip@gmail.com>2015-05-03 16:23:13 +0300
committermiloyip <miloyip@gmail.com>2015-05-03 16:23:13 +0300
commit1c98609adac2401a5916563fe3bb344913f82732 (patch)
tree0b543bbb4762a03de06ddfbdf2ea24a323b326d2
parentae61b7973cff48247ebd1a874e4f47270392e8ca (diff)
Standardize MemoryPoolAllocator::Realloc() also, and improve coverage
-rw-r--r--include/rapidjson/allocators.h3
-rw-r--r--test/unittest/allocatorstest.cpp3
2 files changed, 6 insertions, 0 deletions
diff --git a/include/rapidjson/allocators.h b/include/rapidjson/allocators.h
index 16bf0388..b7042a53 100644
--- a/include/rapidjson/allocators.h
+++ b/include/rapidjson/allocators.h
@@ -189,6 +189,9 @@ public:
if (originalPtr == 0)
return Malloc(newSize);
+ if (newSize == 0)
+ return NULL;
+
// Do not shrink if new size is smaller than original
if (originalSize >= newSize)
return originalPtr;
diff --git a/test/unittest/allocatorstest.cpp b/test/unittest/allocatorstest.cpp
index 3f337242..7b4deeda 100644
--- a/test/unittest/allocatorstest.cpp
+++ b/test/unittest/allocatorstest.cpp
@@ -42,6 +42,9 @@ void TestAllocator(Allocator& a) {
EXPECT_EQ(i, r[i]);
Allocator::Free(r);
+
+ // Realloc to zero size
+ EXPECT_TRUE(a.Realloc(a.Malloc(1), 1, 0) == 0);
}
TEST(Allocator, CrtAllocator) {