]> granicus.if.org Git - gc/commitdiff
Workaround 'null pointer dereference' false positive in push_next_marked
authorIvan Maidanski <ivmai@mail.ru>
Sat, 17 Dec 2016 06:47:10 +0000 (09:47 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Mon, 6 Feb 2017 17:29:24 +0000 (20:29 +0300)
* mark.c [LINT2] (GC_push_next_marked,
GC_push_next_marked_uncollectable): Call ABORT if h is null (to ensure
that null is not passed to GC_push_marked).
* mark.c [!GC_DISABLE_INCREMENTAL && LINT2] (GC_push_next_marked_dirty):
Likewise.
* mark.c [!GC_DISABLE_INCREMENTAL && STUBBORN_ALLOC]
(GC_push_next_marked_dirty): Remove code duplication.

mark.c

diff --git a/mark.c b/mark.c
index c60b0107d8e3a1a4f5fd4fedda2b341880b95056..dc5deaaa38e99472cd7d2ce43cf0cfecc92f6b4f 100644 (file)
--- a/mark.c
+++ b/mark.c
@@ -1882,6 +1882,10 @@ STATIC struct hblk * GC_push_next_marked(struct hblk *h)
       h = GC_next_used_block(h);
       if (h == 0) return(0);
       hhdr = GC_find_header((ptr_t)h);
+    } else {
+#     ifdef LINT2
+        if (NULL == h) ABORT("Bad HDR() definition");
+#     endif
     }
     GC_push_marked(h, hhdr);
     return(h + OBJ_SZ_TO_BLOCKS(hhdr -> hb_sz));
@@ -1900,18 +1904,20 @@ STATIC struct hblk * GC_push_next_marked(struct hblk *h)
           h = GC_next_used_block(h);
           if (h == 0) return(0);
           hhdr = GC_find_header((ptr_t)h);
+        } else {
+#         ifdef LINT2
+            if (NULL == h) ABORT("Bad HDR() definition");
+#         endif
         }
 #       ifdef STUBBORN_ALLOC
           if (hhdr -> hb_obj_kind == STUBBORN) {
-            if (GC_page_was_changed(h) && GC_block_was_dirty(h, hhdr)) {
+            if (GC_page_was_changed(h) && GC_block_was_dirty(h, hhdr))
                 break;
-            }
-          } else {
-            if (GC_block_was_dirty(h, hhdr)) break;
-          }
-#       else
-          if (GC_block_was_dirty(h, hhdr)) break;
+          } else
 #       endif
+        /* else */ {
+          if (GC_block_was_dirty(h, hhdr)) break;
+        }
         h += OBJ_SZ_TO_BLOCKS(hhdr -> hb_sz);
         hhdr = HDR(h);
     }
@@ -1932,6 +1938,10 @@ STATIC struct hblk * GC_push_next_marked_uncollectable(struct hblk *h)
           h = GC_next_used_block(h);
           if (h == 0) return(0);
           hhdr = GC_find_header((ptr_t)h);
+        } else {
+#         ifdef LINT2
+            if (NULL == h) ABORT("Bad HDR() definition");
+#         endif
         }
         if (hhdr -> hb_obj_kind == UNCOLLECTABLE) {
             GC_push_marked(h, hhdr);