Skip to content

Commit

Permalink
Standardize MemoryPoolAllocator::Realloc() also, and improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
miloyip committed May 3, 2015
1 parent ae61b79 commit 1c98609
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/rapidjson/allocators.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ class MemoryPoolAllocator {
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;
Expand Down
3 changes: 3 additions & 0 deletions test/unittest/allocatorstest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 1c98609

Please sign in to comment.