From dbb34733c7d9f985bc779ece40100eb882ccec7e Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 6 Apr 2018 00:42:29 +0300 Subject: [PATCH] Eliminate 'there is pointer arithmetic with NULL' cppcheck warning * extra/msvc_dbg.c (GetDescriptionFromStack): Compare size to 0 instead of comparing description to NULL; mark format argument as used. * extra/msvc_dbg.c (backtrace_symbols): Do not call GetDescriptionFromStack if symbols (description) is NULL but size is non-zero. --- extra/msvc_dbg.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/extra/msvc_dbg.c b/extra/msvc_dbg.c index 42aceeb2..8abe2473 100644 --- a/extra/msvc_dbg.c +++ b/extra/msvc_dbg.c @@ -353,12 +353,15 @@ size_t GetDescriptionFromStack(void* const frames[], size_t count, char*const end = begin + size; char* buffer = begin + (count + 1) * sizeof(char*); size_t i; + (void)format; for (i = 0; i < count; ++i) { - if (description) description[i] = buffer; + 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[count] = NULL; + if (size) + description[count] = NULL; return buffer - begin; } @@ -373,7 +376,8 @@ char** backtrace_symbols(void*const* addresses, int count) { size_t size = GetDescriptionFromStack(addresses, count, NULL, NULL, 0); char** symbols = (char**)malloc(size); - GetDescriptionFromStack(addresses, count, NULL, symbols, size); + if (symbols != NULL) + GetDescriptionFromStack(addresses, count, NULL, symbols, size); return symbols; } -- 2.50.1