From c1976a3967b467d09589d306712abef0958048b3 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Wed, 7 Nov 2018 10:15:31 +0300 Subject: [PATCH] Workaround 'pointer addition with NULL pointer' cppcheck error in msvc_dbg * extra/msvc_dbg.c (GetDescriptionFromStack): Change type of begin, end, buffer local variables from char* to GC_ULONG_PTR; do not update size local variable value; do not store elements to description[] if description is NULL (instead of checking of size is non-zero). --- extra/msvc_dbg.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/extra/msvc_dbg.c b/extra/msvc_dbg.c index b7ef8d9..858c67e 100644 --- a/extra/msvc_dbg.c +++ b/extra/msvc_dbg.c @@ -352,18 +352,18 @@ size_t GetDescriptionFromStack(void* const frames[], size_t count, const char* format, char* description[], size_t size) { - char*const begin = (char*)description; - char*const end = begin + size; - char* buffer = begin + (count + 1) * sizeof(char*); + const GC_ULONG_PTR begin = (GC_ULONG_PTR)description; + const GC_ULONG_PTR end = begin + size; + GC_ULONG_PTR buffer = begin + (count + 1) * sizeof(char*); size_t i; (void)format; for (i = 0; i < count; ++i) { - if (size) - description[i] = buffer; - size = (GC_ULONG_PTR)end < (GC_ULONG_PTR)buffer ? 0 : end - buffer; - buffer += 1 + GetDescriptionFromAddress(frames[i], NULL, buffer, size); + if (description) + description[i] = (char*)buffer; + buffer += 1 + GetDescriptionFromAddress(frames[i], NULL, (char*)buffer, + end < buffer ? 0 : end - buffer); } - if (size) + if (description) description[count] = NULL; return buffer - begin; } -- 2.7.4