From 9d8df28c1dd92be8480fae8026fed0aa2c0d8cdd Mon Sep 17 00:00:00 2001 From: Patrick Cheng Date: Fri, 30 Sep 2016 10:47:00 -0700 Subject: [PATCH 1/3] added assertion to help suppress clang warnings --- include/rapidjson/internal/stack.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/rapidjson/internal/stack.h b/include/rapidjson/internal/stack.h index 022c9aab4..54ac77a82 100644 --- a/include/rapidjson/internal/stack.h +++ b/include/rapidjson/internal/stack.h @@ -113,6 +113,7 @@ class Stack { // Expansion is run very infrequently, so it is moved to another (probably non-inline) function. template RAPIDJSON_FORCEINLINE void Reserve(size_t count = 1) { + RAPIDJSON_ASSERT(stackTop_); // Expand the stack if needed if (RAPIDJSON_UNLIKELY(stackTop_ + sizeof(T) * count > stackEnd_)) Expand(count); @@ -126,6 +127,7 @@ class Stack { template RAPIDJSON_FORCEINLINE T* PushUnsafe(size_t count = 1) { + RAPIDJSON_ASSERT(stackTop_); RAPIDJSON_ASSERT(stackTop_ + sizeof(T) * count <= stackEnd_); T* ret = reinterpret_cast(stackTop_); stackTop_ += sizeof(T) * count; From 91a803d46394a668fd5cb51bd1b4dbea9b4b2fb0 Mon Sep 17 00:00:00 2001 From: Patrick Cheng Date: Fri, 30 Sep 2016 11:12:23 -0700 Subject: [PATCH 2/3] Reserve() is sometimes called when stackTop_ is null. The assert is invalid. --- include/rapidjson/internal/stack.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/rapidjson/internal/stack.h b/include/rapidjson/internal/stack.h index 54ac77a82..26b716d2b 100644 --- a/include/rapidjson/internal/stack.h +++ b/include/rapidjson/internal/stack.h @@ -113,7 +113,6 @@ class Stack { // Expansion is run very infrequently, so it is moved to another (probably non-inline) function. template RAPIDJSON_FORCEINLINE void Reserve(size_t count = 1) { - RAPIDJSON_ASSERT(stackTop_); // Expand the stack if needed if (RAPIDJSON_UNLIKELY(stackTop_ + sizeof(T) * count > stackEnd_)) Expand(count); From 95224aff7dff65c448dca374b4c7fccc32680e5c Mon Sep 17 00:00:00 2001 From: Patrick Cheng Date: Fri, 30 Sep 2016 13:44:15 -0700 Subject: [PATCH 3/3] When length is 0, the code does nothing, so skip it completely. Previously, os.Push(0) would do nothing as well. But with the newly added assertion, is the stack is empty, it will fail the assertion. --- include/rapidjson/reader.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index 19f8849b1..e3523a0d6 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -948,11 +948,13 @@ class GenericReader { #else length = static_cast(__builtin_ffs(r) - 1); #endif - char* q = reinterpret_cast(os.Push(length)); - for (size_t i = 0; i < length; i++) - q[i] = p[i]; + if (length != 0) { + char* q = reinterpret_cast(os.Push(length)); + for (size_t i = 0; i < length; i++) + q[i] = p[i]; - p += length; + p += length; + } break; } _mm_storeu_si128(reinterpret_cast<__m128i *>(os.Push(16)), s);