From 1c98609adac2401a5916563fe3bb344913f82732 Mon Sep 17 00:00:00 2001 From: miloyip Date: Sun, 3 May 2015 21:23:13 +0800 Subject: Standardize MemoryPoolAllocator::Realloc() also, and improve coverage --- include/rapidjson/allocators.h | 3 +++ test/unittest/allocatorstest.cpp | 3 +++ 2 files changed, 6 insertions(+) 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) { -- cgit v1.2.3