]> granicus.if.org Git - gc/commitdiff
Workaround more 'void pointers in calculations' cppcheck warnings
authorIvan Maidanski <ivmai@mail.ru>
Mon, 17 Oct 2016 07:53:19 +0000 (10:53 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 1 Nov 2016 23:06:36 +0000 (02:06 +0300)
* include/new_gc_alloc.h (single_client_gc_alloc_template::allocate,
single_client_gc_alloc_template::ptr_free_allocate,
single_client_gc_alloc_template::deallocate,
single_client_gc_alloc_template::ptr_free_deallocate,
single_client_traceable_alloc_template::allocate,
single_client_traceable_alloc_template::ptr_free_allocate,
single_client_traceable_alloc_template::deallocate,
single_client_traceable_alloc_template::ptr_free_deallocate): Replace
GC_Xobjfreelist_ptr+nwords with &GC_Xobjfreelist_ptr[nwords].
* reclaim.c (GC_start_reclaim): Replace fop++ with (*(word**)&fop)++.
* thread_local_alloc.c (return_freelists): Replace gfl+i with &gfl[i].

include/new_gc_alloc.h
reclaim.c
thread_local_alloc.c

index ae66647942ef5fe109ba4c8809f7702fdd72c467..0833fd82489974ad71bd4859de5de3c364e2f9d1 100644 (file)
@@ -194,8 +194,9 @@ class single_client_gc_alloc_template {
             void * op;
 
             if (n > GC_max_fast_bytes) return GC_malloc(n);
-            flh = GC_objfreelist_ptr + nwords;
-            if (0 == (op = *flh)) {
+            flh = &GC_objfreelist_ptr[nwords];
+            op = *flh;
+            if (0 == op) {
                 return GC_aux::GC_out_of_line_malloc(nwords, GC_NORMAL);
             }
             *flh = GC_obj_link(op);
@@ -209,8 +210,9 @@ class single_client_gc_alloc_template {
             void * op;
 
             if (n > GC_max_fast_bytes) return GC_malloc_atomic(n);
-            flh = GC_aobjfreelist_ptr + nwords;
-            if (0 == (op = *flh)) {
+            flh = &GC_aobjfreelist_ptr[nwords];
+            op = *flh;
+            if (0 == op) {
                 return GC_aux::GC_out_of_line_malloc(nwords, GC_PTRFREE);
             }
             *flh = GC_obj_link(op);
@@ -223,7 +225,8 @@ class single_client_gc_alloc_template {
                 GC_free(p);
             } else {
                 size_t nwords = GC_round_up(n);
-                void ** flh = GC_objfreelist_ptr + nwords;
+                void ** flh = &GC_objfreelist_ptr[nwords];
+
                 GC_obj_link(p) = *flh;
                 memset(reinterpret_cast<char *>(p) + GC_bytes_per_word, 0,
                        GC_bytes_per_word * (nwords - 1));
@@ -237,7 +240,8 @@ class single_client_gc_alloc_template {
                 GC_free(p);
             } else {
                 size_t nwords = GC_round_up(n);
-                void ** flh = GC_aobjfreelist_ptr + nwords;
+                void ** flh = &GC_aobjfreelist_ptr[nwords];
+
                 GC_obj_link(p) = *flh;
                 *flh = p;
                 GC_aux::GC_bytes_recently_freed += nwords * GC_bytes_per_word;
@@ -258,8 +262,9 @@ class single_client_traceable_alloc_template {
             void * op;
 
             if (n > GC_max_fast_bytes) return GC_malloc_uncollectable(n);
-            flh = GC_uobjfreelist_ptr + nwords;
-            if (0 == (op = *flh)) {
+            flh = &GC_uobjfreelist_ptr[nwords];
+            op = *flh;
+            if (0 == op) {
                 return GC_aux::GC_out_of_line_malloc(nwords, GC_UNCOLLECTABLE);
             }
             *flh = GC_obj_link(op);
@@ -274,8 +279,9 @@ class single_client_traceable_alloc_template {
             void * op;
 
             if (n > GC_max_fast_bytes) return GC_malloc_atomic_uncollectable(n);
-            flh = GC_auobjfreelist_ptr + nwords;
-            if (0 == (op = *flh)) {
+            flh = &GC_auobjfreelist_ptr[nwords];
+            op = *flh;
+            if (0 == op) {
                 return GC_aux::GC_out_of_line_malloc(nwords, GC_AUNCOLLECTABLE);
             }
             *flh = GC_obj_link(op);
@@ -289,7 +295,8 @@ class single_client_traceable_alloc_template {
                 GC_free(p);
             } else {
                 size_t nwords = GC_round_up_uncollectable(n);
-                void ** flh = GC_uobjfreelist_ptr + nwords;
+                void ** flh = &GC_uobjfreelist_ptr[nwords];
+
                 GC_obj_link(p) = *flh;
                 *flh = p;
                 GC_aux::GC_uncollectable_bytes_recently_freed +=
@@ -302,7 +309,8 @@ class single_client_traceable_alloc_template {
                 GC_free(p);
             } else {
                 size_t nwords = GC_round_up_uncollectable(n);
-                void ** flh = GC_auobjfreelist_ptr + nwords;
+                void ** flh = &GC_auobjfreelist_ptr[nwords];
+
                 GC_obj_link(p) = *flh;
                 *flh = p;
                 GC_aux::GC_uncollectable_bytes_recently_freed +=
index e266e8b34c0a204b27e38d677545f030e89ff784..2a113e7da90daa634c7da9d54fd0c778a471016c 100644 (file)
--- a/reclaim.c
+++ b/reclaim.c
@@ -625,7 +625,7 @@ GC_INNER void GC_start_reclaim(GC_bool report_if_found)
             void **lim = &(GC_obj_kinds[kind].ok_freelist[MAXOBJGRANULES+1]);
 
             for (fop = GC_obj_kinds[kind].ok_freelist;
-                 (word)fop < (word)lim; fop++) {
+                 (word)fop < (word)lim; (*(word **)&fop)++) {
               if (*fop != 0) {
                 if (should_clobber) {
                   GC_clear_fl_links(fop);
index cb38724bc17d11e8d5e195cd059474a5aa305943..ae1286db1ac51fcd5fb9cbecf99a831c5e928630 100644 (file)
@@ -61,7 +61,7 @@ static void return_freelists(void **fl, void **gfl)
 
     for (i = 1; i < TINY_FREELISTS; ++i) {
         if ((word)(fl[i]) >= HBLKSIZE) {
-          return_single_freelist(fl[i], gfl+i);
+          return_single_freelist(fl[i], &gfl[i]);
         }
         /* Clear fl[i], since the thread structure may hang around.     */
         /* Do it in a way that is likely to trap if we access it.       */
@@ -72,7 +72,7 @@ static void return_freelists(void **fl, void **gfl)
       if (fl[0] == ERROR_FL) return;
 #   endif
     if ((word)(fl[0]) >= HBLKSIZE) {
-        return_single_freelist(fl[0], gfl+1);
+        return_single_freelist(fl[0], &gfl[1]);
     }
 }