summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2019-09-11 01:11:04 +0300
committerIvan Maidanski <ivmai@mail.ru>2019-09-11 01:11:04 +0300
commita20818be9ec660588af325d82e515ebb75bd9905 (patch)
treecf0766e19fa5ee4380f2236ab4bf088b7cd5d330
parentfe3a50824e878995999462843aff679d52e9f61b (diff)
downloadbdwgc-a20818be9ec660588af325d82e515ebb75bd9905.tar.gz
Workaround 'argument to function is always 1' cppcheck false positives
* allchblk.c (GC_print_hblkfreelist): Replace "while(p!=0)" with "while(p)"; add a marker that the change is for cppcheck. * allchblk.c (GC_free_block_ending_at, GC_add_to_fl, GC_split_block, GC_allochblk_nth, GC_freehblk): Replace "if(p!=0)" with "if(p)". * alloc.c (GC_set_fl_marks): Likewise. * extra/MacOS.c (GC_MacFreeTemporaryMemory): Likewise. * mallocx.c (GC_generic_malloc_many): Likewise. * allchblk.c (GC_allochblk_nth): Replace "if(0==p)" with "if(p){}else". * malloc.c (GC_free): Likewise. * malloc.c (GC_generic_malloc_uncollectable): Replace "if(0==p)return 0;<code>;return p;" with "if(p){<code>}return p;". * mallocx.c (GC_generic_malloc_many): Replace "p+=v;while((p2=*p)!=0)" with "for(p+=v;(p2=*p)!=0;)". * reclaim.c (GC_continue_reclaim, GC_reclaim_all): Likewise.
-rw-r--r--allchblk.c20
-rw-r--r--alloc.c2
-rw-r--r--extra/MacOS.c2
-rw-r--r--malloc.c17
-rw-r--r--mallocx.c5
-rw-r--r--reclaim.c10
6 files changed, 31 insertions, 25 deletions
diff --git a/allchblk.c b/allchblk.c
index e5bb6bd1..a70ee73c 100644
--- a/allchblk.c
+++ b/allchblk.c
@@ -130,7 +130,7 @@ void GC_print_hblkfreelist(void)
if (0 != h) GC_printf("Free list %u (total size %lu):\n",
i, (unsigned long)GC_free_bytes[i]);
- while (h != 0) {
+ while (h /* != NULL */) { /* CPPCHECK */
hdr * hhdr = HDR(h);
GC_printf("\t%p size %lu %s black listed\n",
@@ -345,7 +345,7 @@ STATIC struct hblk * GC_free_block_ending_at(struct hblk *h)
}
}
p = GC_prev_block(h - 1);
- if (0 != p) {
+ if (p /* != NULL */) { /* CPPCHECK */
phdr = HDR(p);
if (HBLK_IS_FREE(phdr) && (ptr_t)p + phdr -> hb_sz == (ptr_t)h) {
return p;
@@ -378,7 +378,7 @@ STATIC void GC_add_to_fl(struct hblk *h, hdr *hhdr)
GC_ASSERT(GC_free_bytes[index] <= GC_large_free_bytes);
hhdr -> hb_next = second;
hhdr -> hb_prev = 0;
- if (0 != second) {
+ if (second /* != NULL */) { /* CPPCHECK */
hdr * second_hdr;
GET_HDR(second, second_hdr);
@@ -553,12 +553,12 @@ STATIC void GC_split_block(struct hblk *h, hdr *hhdr, struct hblk *n,
nhdr -> hb_next = next;
nhdr -> hb_sz = total_size - h_size;
nhdr -> hb_flags = 0;
- if (0 != prev) {
+ if (prev /* != NULL */) { /* CPPCHECK */
HDR(prev) -> hb_next = n;
} else {
GC_hblkfreelist[index] = n;
}
- if (0 != next) {
+ if (next /* != NULL */) {
HDR(next) -> hb_prev = n;
}
GC_ASSERT(GC_free_bytes[index] > h_size);
@@ -663,7 +663,11 @@ GC_allochblk_nth(size_t sz, int kind, unsigned flags, int n, int may_split)
for (hbp = GC_hblkfreelist[n];; hbp = hhdr -> hb_next) {
signed_word size_avail; /* bytes available in this block */
- if (NULL == hbp) return NULL;
+ if (hbp /* != NULL */) {
+ /* CPPCHECK */
+ } else {
+ return NULL;
+ }
GET_HDR(hbp, hhdr); /* set hhdr value */
size_avail = (signed_word)hhdr->hb_sz;
if (size_avail < size_needed) continue;
@@ -673,7 +677,7 @@ GC_allochblk_nth(size_t sz, int kind, unsigned flags, int n, int may_split)
/* This prevents us from disassembling a single large */
/* block to get tiny blocks. */
thishbp = hhdr -> hb_next;
- if (thishbp != 0) {
+ if (thishbp /* != NULL */) { /* CPPCHECK */
signed_word next_size;
GET_HDR(thishbp, thishdr);
@@ -875,7 +879,7 @@ GC_INNER void GC_freehblk(struct hblk *hbp)
GC_remove_header(next);
}
/* Coalesce with predecessor, if possible. */
- if (0 != prev) {
+ if (prev /* != NULL */) { /* CPPCHECK */
prevhdr = HDR(prev);
if (IS_MAPPED(prevhdr)
&& (signed_word)(hhdr -> hb_sz + prevhdr -> hb_sz) > 0) {
diff --git a/alloc.c b/alloc.c
index 45fd0869..5e3816e9 100644
--- a/alloc.c
+++ b/alloc.c
@@ -916,7 +916,7 @@ STATIC GC_bool GC_stopped_mark(GC_stop_func stop_func)
/* Set all mark bits for the free list whose first entry is q */
GC_INNER void GC_set_fl_marks(ptr_t q)
{
- if (q != NULL) {
+ if (q /* != NULL */) { /* CPPCHECK */
struct hblk *h = HBLKPTR(q);
struct hblk *last_h = h;
hdr *hhdr = HDR(h);
diff --git a/extra/MacOS.c b/extra/MacOS.c
index 624b383d..363b40ec 100644
--- a/extra/MacOS.c
+++ b/extra/MacOS.c
@@ -126,7 +126,7 @@ void GC_MacFreeTemporaryMemory(void)
long totalMemoryUsed = 0;
# endif
TemporaryMemoryHandle tempMemBlock = theTemporaryMemory;
- while (tempMemBlock != NULL) {
+ while (tempMemBlock /* != NULL */) {
TemporaryMemoryHandle nextBlock = (**tempMemBlock).nextBlock;
# if !defined(SHARED_LIBRARY_BUILD)
totalMemoryUsed += GetHandleSize((Handle)tempMemBlock);
diff --git a/malloc.c b/malloc.c
index f21d11c2..7e35ee8b 100644
--- a/malloc.c
+++ b/malloc.c
@@ -381,14 +381,11 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_generic_malloc_uncollectable(
}
GC_ASSERT(0 == op || GC_is_marked(op));
} else {
- hdr * hhdr;
-
- op = GC_generic_malloc(lb, k);
- if (NULL == op)
- return NULL;
+ op = GC_generic_malloc(lb, k);
+ if (op /* != NULL */) { /* CPPCHECK */
+ hdr * hhdr = HDR(op);
GC_ASSERT(((word)op & (HBLKSIZE - 1)) == 0); /* large block */
- hhdr = HDR(op);
/* We don't need the lock here, since we have an undisguised */
/* pointer. We do need to hold the lock while we adjust */
/* mark bits. */
@@ -401,6 +398,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_generic_malloc_uncollectable(
# endif
hhdr -> hb_n_marks = 1;
UNLOCK();
+ }
}
return op;
}
@@ -564,8 +562,13 @@ GC_API void GC_CALL GC_free(void * p)
struct obj_kind * ok;
DCL_LOCK_STATE;
- if (p == 0) return;
+ if (p /* != NULL */) {
+ /* CPPCHECK */
+ } else {
/* Required by ANSI. It's not my fault ... */
+ return;
+ }
+
# ifdef LOG_ALLOCS
GC_log_printf("GC_free(%p) after GC #%lu\n",
p, (unsigned long)GC_gc_no);
diff --git a/mallocx.c b/mallocx.c
index 1aa45699..217988a8 100644
--- a/mallocx.c
+++ b/mallocx.c
@@ -349,8 +349,7 @@ GC_API void GC_CALL GC_generic_malloc_many(size_t lb, int k, void **result)
struct hblk * hbp;
hdr * hhdr;
- rlh += lg;
- while ((hbp = *rlh) != 0) {
+ for (rlh += lg; (hbp = *rlh) != NULL; ) {
hhdr = HDR(hbp);
*rlh = hhdr -> hb_next;
GC_ASSERT(hhdr -> hb_sz == lb);
@@ -441,7 +440,7 @@ GC_API void GC_CALL GC_generic_malloc_many(size_t lb, int k, void **result)
/* Next try to allocate a new block worth of objects of this size. */
{
struct hblk *h = GC_allochblk(lb, k, 0);
- if (h != 0) {
+ if (h /* != NULL */) { /* CPPCHECK */
if (IS_UNCOLLECTABLE(k)) GC_set_hdr_marks(HDR(h));
GC_bytes_allocd += HBLKSIZE - HBLKSIZE % lb;
# ifdef PARALLEL_MARK
diff --git a/reclaim.c b/reclaim.c
index e0e53e1d..1da2c932 100644
--- a/reclaim.c
+++ b/reclaim.c
@@ -710,9 +710,10 @@ GC_INNER void GC_continue_reclaim(word sz /* granules */, int kind)
struct hblk ** rlh = ok -> ok_reclaim_list;
void **flh = &(ok -> ok_freelist[sz]);
- if (rlh == 0) return; /* No blocks of this kind. */
- rlh += sz;
- while ((hbp = *rlh) != 0) {
+ if (NULL == rlh)
+ return; /* No blocks of this kind. */
+
+ for (rlh += sz; (hbp = *rlh) != NULL; ) {
hhdr = HDR(hbp);
*rlh = hhdr -> hb_next;
GC_reclaim_small_nonempty_block(hbp, hhdr -> hb_sz, FALSE);
@@ -751,8 +752,7 @@ GC_INNER GC_bool GC_reclaim_all(GC_stop_func stop_func, GC_bool ignore_old)
rlp = ok -> ok_reclaim_list;
if (rlp == 0) continue;
for (sz = 1; sz <= MAXOBJGRANULES; sz++) {
- rlh = rlp + sz;
- while ((hbp = *rlh) != 0) {
+ for (rlh = rlp + sz; (hbp = *rlh) != NULL; ) {
if (stop_func != (GC_stop_func)0 && (*stop_func)()) {
return(FALSE);
}