Eliminate 'suspicious pointer subtraction' cppcheck warning (gc_cpp)
authorIvan Maidanski <ivmai@mail.ru>
Wed, 26 Oct 2016 08:13:29 +0000 (11:13 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 26 Oct 2016 08:13:48 +0000 (11:13 +0300)
* include/gc_cpp.h (gc_cleanup::gc_cleanup): Define this_ptr void
pointer; use this_ptr instead of this keyword to outline that the
pointer subtraction is intentional (i.e., "this->" was not intended).

include/gc_cpp.h

index b0ab260..9110633 100644 (file)
@@ -428,11 +428,12 @@ inline gc_cleanup::gc_cleanup()
 {
   GC_finalization_proc oldProc;
   void* oldData;
-  void* base = GC_base((void*) this);
+  void* this_ptr = (void*)this;
+  void* base = GC_base(this_ptr);
   if (base != 0) {
     // Don't call the debug version, since this is a real base address.
     GC_register_finalizer_ignore_self(base, (GC_finalization_proc) cleanup,
-                                      (void*) ((char*) this - (char*) base),
+                                      (void*)((char*)this_ptr - (char*)base),
                                       &oldProc, &oldData);
     if (oldProc != 0) {
       GC_register_finalizer_ignore_self(base, oldProc, oldData, 0, 0);