Merge pull request #140 from kojik1010/mempool_null_check

make MemoryPoolAllocator's Malloc work after Clear if a buffer was not supplied by the user
This commit is contained in:
Milo Yip 2014-09-11 16:52:36 +08:00
commit 2475e9524b

View File

@ -170,7 +170,7 @@ public:
//! Allocates a memory block. (concept Allocator)
void* Malloc(size_t size) {
size = RAPIDJSON_ALIGN(size);
if (chunkHead_->size + size > chunkHead_->capacity)
if (chunkHead_ == 0 || chunkHead_->size + size > chunkHead_->capacity)
AddChunk(chunk_capacity_ > size ? chunk_capacity_ : size);
void *buffer = reinterpret_cast<char *>(chunkHead_ + 1) + chunkHead_->size;