From 0e9eabdb189f520441cb0a0161df9ca3881f89b1 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Wed, 23 Jun 2021 09:24:52 -0700 Subject: [PATCH] Cherry-pick UBSAN fix from https://github.com/Tencent/rapidjson/commit/16872af88915176f49e389defb167f899e2c230a --- fdbclient/rapidjson/internal/stack.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fdbclient/rapidjson/internal/stack.h b/fdbclient/rapidjson/internal/stack.h index 7ab15d42a0..fa43aa0171 100644 --- a/fdbclient/rapidjson/internal/stack.h +++ b/fdbclient/rapidjson/internal/stack.h @@ -17,6 +17,7 @@ #include "../allocators.h" #include "swap.h" +#include #if defined(__clang__) RAPIDJSON_DIAG_PUSH @@ -106,7 +107,7 @@ public: template RAPIDJSON_FORCEINLINE void Reserve(size_t count = 1) { // Expand the stack if needed - if (RAPIDJSON_UNLIKELY(stackTop_ + sizeof(T) * count > stackEnd_)) + if (RAPIDJSON_UNLIKELY(static_cast(sizeof(T) * count) > (stackEnd_ - stackTop_))) Expand(count); } @@ -118,7 +119,7 @@ public: template RAPIDJSON_FORCEINLINE T* PushUnsafe(size_t count = 1) { - RAPIDJSON_ASSERT(stackTop_ + sizeof(T) * count <= stackEnd_); + RAPIDJSON_ASSERT(static_cast(sizeof(T) * count) <= (stackEnd_ - stackTop_)); T* ret = reinterpret_cast(stackTop_); stackTop_ += sizeof(T) * count; return ret;