Merge pull request #727 from mapbox/silence-dereference-null-pointer

Silence false positive clang-tidy warning
This commit is contained in:
Milo Yip 2019-03-06 09:33:13 +08:00 committed by GitHub
commit 3cf4f7c5a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,7 @@
#include "../allocators.h" #include "../allocators.h"
#include "swap.h" #include "swap.h"
#include <cstddef>
#if defined(__clang__) #if defined(__clang__)
RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PUSH
@ -114,7 +115,7 @@ public:
template<typename T> template<typename T>
RAPIDJSON_FORCEINLINE void Reserve(size_t count = 1) { RAPIDJSON_FORCEINLINE void Reserve(size_t count = 1) {
// Expand the stack if needed // Expand the stack if needed
if (RAPIDJSON_UNLIKELY(stackTop_ + sizeof(T) * count > stackEnd_)) if (RAPIDJSON_UNLIKELY(static_cast<std::ptrdiff_t>(sizeof(T) * count) > (stackEnd_ - stackTop_)))
Expand<T>(count); Expand<T>(count);
} }
@ -127,7 +128,7 @@ public:
template<typename T> template<typename T>
RAPIDJSON_FORCEINLINE T* PushUnsafe(size_t count = 1) { RAPIDJSON_FORCEINLINE T* PushUnsafe(size_t count = 1) {
RAPIDJSON_ASSERT(stackTop_); RAPIDJSON_ASSERT(stackTop_);
RAPIDJSON_ASSERT(stackTop_ + sizeof(T) * count <= stackEnd_); RAPIDJSON_ASSERT(static_cast<std::ptrdiff_t>(sizeof(T) * count) <= (stackEnd_ - stackTop_));
T* ret = reinterpret_cast<T*>(stackTop_); T* ret = reinterpret_cast<T*>(stackTop_);
stackTop_ += sizeof(T) * count; stackTop_ += sizeof(T) * count;
return ret; return ret;