From: Ivan Maidanski Date: Mon, 17 Oct 2016 07:53:19 +0000 (+0300) Subject: Workaround more 'void pointers in calculations' cppcheck warnings X-Git-Tag: v7.6.2~346 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2c572396237d92ea2cfb6655531917062dbd148d;p=gc Workaround more 'void pointers in calculations' cppcheck warnings * 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]. --- diff --git a/include/new_gc_alloc.h b/include/new_gc_alloc.h index ae666479..0833fd82 100644 --- a/include/new_gc_alloc.h +++ b/include/new_gc_alloc.h @@ -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(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 += diff --git a/reclaim.c b/reclaim.c index e266e8b3..2a113e7d 100644 --- 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); diff --git a/thread_local_alloc.c b/thread_local_alloc.c index cb38724b..ae1286db 100644 --- a/thread_local_alloc.c +++ b/thread_local_alloc.c @@ -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]); } }