Add asserts to prevent UB

This commit is contained in:
Rodion Malinovsky 2015-09-16 14:53:12 +03:00
parent 539e57225b
commit 8604ba0f1c
2 changed files with 8 additions and 2 deletions

View File

@ -1989,7 +1989,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(); }

View File

@ -134,7 +134,10 @@ public:
template<typename T>
T* Bottom() { return (T*)stack_; }
Allocator& GetAllocator() { return *allocator_; }
Allocator& GetAllocator() {
RAPIDJSON_ASSERT(allocator_);
return *allocator_;
}
bool Empty() const { return stackTop_ == stack_; }
size_t GetSize() const { return static_cast<size_t>(stackTop_ - stack_); }
size_t GetCapacity() const { return static_cast<size_t>(stackEnd_ - stack_); }