Workaround 'pointer addition with NULL pointer' cppcheck error in msvc_dbg
authorIvan Maidanski <ivmai@mail.ru>
Wed, 7 Nov 2018 07:15:31 +0000 (10:15 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 7 Nov 2018 07:40:40 +0000 (10:40 +0300)
* 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

index b7ef8d9..858c67e 100644 (file)
@@ -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;
 }