diff --git a/include/rapidjson/internal/stack.h b/include/rapidjson/internal/stack.h index 299e651ed..5c5398c35 100644 --- a/include/rapidjson/internal/stack.h +++ b/include/rapidjson/internal/stack.h @@ -126,6 +126,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; diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index 71916c0ae..dbb5e16fa 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -934,11 +934,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);