]> granicus.if.org Git - gc/commitdiff
Workaround 'int shift by negative amount' false code defect in finalize
authorIvan Maidanski <ivmai@mail.ru>
Tue, 16 May 2017 21:40:33 +0000 (00:40 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 24 May 2017 21:30:13 +0000 (00:30 +0300)
(Cherry-pick commits d46fbe059e156e from 'master' branch.)

* finalize.c (GC_register_disappearing_link_inner,
GC_register_finalizer_inner): Replace GC_ASSERT (for log_size) with
a conditional ABORT if LINT2.
* finalize.c [GC_ASSERTIONS || LINT2] (GC_finalize): Replace GC_ASSERT
(for curr_fo and log_fo_table_size) with a conditional ABORT.

finalize.c

index 50caaa553c32eb339e576486692394f3d965c46c..4b6527900c7c19ebf10656b501963745363ef41b 100644 (file)
@@ -158,7 +158,9 @@ STATIC int GC_register_disappearing_link_inner(
         || dl_hashtbl -> entries > ((word)1 << dl_hashtbl -> log_size)) {
         GC_grow_table((struct hash_chain_entry ***)&dl_hashtbl -> head,
                       &dl_hashtbl -> log_size);
-        GC_ASSERT(dl_hashtbl->log_size >= 0);
+#       ifdef LINT2
+          if (dl_hashtbl->log_size < 0) ABORT("log_size is negative");
+#       endif
         GC_COND_LOG_PRINTF("Grew %s table to %u entries\n", tbl_log_name,
                            1 << (unsigned)dl_hashtbl -> log_size);
     }
@@ -650,7 +652,9 @@ STATIC void GC_register_finalizer_inner(void * obj,
         || GC_fo_entries > ((word)1 << log_fo_table_size)) {
         GC_grow_table((struct hash_chain_entry ***)&GC_fnlz_roots.fo_head,
                       &log_fo_table_size);
-        GC_ASSERT(log_fo_table_size >= 0);
+#       ifdef LINT2
+          if (log_fo_table_size < 0) ABORT("log_size is negative");
+#       endif
         GC_COND_LOG_PRINTF("Grew fo table to %u entries\n",
                            1 << (unsigned)log_fo_table_size);
     }
@@ -1045,7 +1049,10 @@ GC_INNER void GC_finalize(void)
        other finalizable objects */
       if (need_unreachable_finalization) {
         curr_fo = GC_fnlz_roots.finalize_now;
-        GC_ASSERT(NULL == curr_fo || log_fo_table_size >= 0);
+#       if defined(GC_ASSERTIONS) || defined(LINT2)
+          if (curr_fo != NULL && log_fo_table_size < 0)
+            ABORT("log_size is negative");
+#       endif
         prev_fo = NULL;
         while (curr_fo != NULL) {
           next_fo = fo_next(curr_fo);