]> granicus.if.org Git - gc/commitdiff
Workaround 'argument to function is always 1' cppcheck false positives
authorIvan Maidanski <ivmai@mail.ru>
Tue, 10 Sep 2019 22:11:04 +0000 (01:11 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 10 Sep 2019 22:11:04 +0000 (01:11 +0300)
* 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.

allchblk.c
alloc.c
extra/MacOS.c
malloc.c
mallocx.c
reclaim.c

index e5bb6bd16fd70cd6443d57f897df01b3b3a363ec..a70ee73c85ab92b4312366085c242ea6c416da8d 100644 (file)
@@ -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 45fd0869d6ca925db7462c59ca97d8be9cf94ca9..5e3816e94faf46f5dbd28f222c4b2a7e61e1221c 100644 (file)
--- 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);
index 624b383d4e36f2f86b7bb57df2472297326b0cf1..363b40ec4b83a2ab00503ea560a8940dba0bda17 100644 (file)
@@ -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);
index f21d11c21bec471d53feb0d781ef064a0d23ead2..7e35ee8b08cd40fa2f525d7486c77fea5c06cd53 100644 (file)
--- 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);
index 1aa45699d1f0e4e6ac37d9dc7f21f7846b8fcbc4..217988a80f1646e0838012b667145eb72cc1bc6f 100644 (file)
--- 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
index e0e53e1d011b7aaaedced442fa3293b323ea4daf..1da2c932d8abb2030c78b8f443c5ffa51d20fcb3 100644 (file)
--- 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);
                 }