diff --git a/include/rapidjson/document.h b/include/rapidjson/document.h index f5c1be9..0a5a7b2 100644 --- a/include/rapidjson/document.h +++ b/include/rapidjson/document.h @@ -1887,7 +1887,8 @@ public: template GenericDocument& ParseStream(InputStream& is) { ValueType::SetNull(); // Remove existing root if exist - GenericReader reader(&stack_.GetAllocator()); + GenericReader reader( + stack_.HasAllocator() ? &stack_.GetAllocator() : 0); ClearStackOnExit scope(*this); parseResult_ = reader.template Parse(is, *this); if (parseResult_) { @@ -1989,7 +1990,10 @@ public: //!@} //! Get the allocator of this document. - Allocator& GetAllocator() { return *allocator_; } + Allocator& GetAllocator() { + RAPIDJSON_ASSERT(allocator_); + return *allocator_; + } //! Get the capacity of stack in bytes. size_t GetStackCapacity() const { return stack_.GetCapacity(); } diff --git a/include/rapidjson/internal/stack.h b/include/rapidjson/internal/stack.h index 0d4a7f7..82f23dd 100644 --- a/include/rapidjson/internal/stack.h +++ b/include/rapidjson/internal/stack.h @@ -134,7 +134,14 @@ public: template T* Bottom() { return (T*)stack_; } - Allocator& GetAllocator() { return *allocator_; } + bool HasAllocator() const { + return allocator_ != 0; + } + + Allocator& GetAllocator() { + RAPIDJSON_ASSERT(allocator_); + return *allocator_; + } bool Empty() const { return stackTop_ == stack_; } size_t GetSize() const { return static_cast(stackTop_ - stack_); } size_t GetCapacity() const { return static_cast(stackEnd_ - stack_); }