]> granicus.if.org Git - gc/commitdiff
Eliminate 'comparison is always false' static analyzer warning in finalize
authorIvan Maidanski <ivmai@mail.ru>
Wed, 28 Sep 2016 07:04:39 +0000 (10:04 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 28 Sep 2016 07:04:39 +0000 (10:04 +0300)
GC_enqueue_all_finalizers code refactoring is done (removal of the
unreachable statement) to eliminate the warning.

* finalize.c (GC_enqueue_all_finalizers): Remove "prev_fo" local
variable; remove "register" keyword for local variables;
remove the pointer to the chain of hash table entries from the roots
(i.e. setting the roots pointer to null) at the beginning of processing
the chain (instead of updating the roots pointer on deletion of each
entry and finally setting it to null); remove fo_set_next(prev_fo) as
it is never called (because prev_fo was always null); update
GC_fo_entries only when the whole table processed (i.e. all items
removed).

finalize.c

index 514e42d98cde6e05c3fcf845614b39114a27dc11..1b570c2cd99057939a2a6275ecf1fb73a60a0b43 100644 (file)
@@ -1088,29 +1088,22 @@ GC_INNER void GC_finalize(void)
   /* Enqueue all remaining finalizers to be run - Assumes lock is held. */
   STATIC void GC_enqueue_all_finalizers(void)
   {
-    struct finalizable_object * curr_fo, * prev_fo, * next_fo;
+    struct finalizable_object * curr_fo, * next_fo;
     ptr_t real_ptr;
-    register int i;
+    int i;
     int fo_size;
 
     fo_size = log_fo_table_size == -1 ? 0 : 1 << log_fo_table_size;
     GC_bytes_finalized = 0;
     for (i = 0; i < fo_size; i++) {
       curr_fo = GC_fnlz_roots.fo_head[i];
-      prev_fo = NULL;
+      GC_fnlz_roots.fo_head[i] = NULL;
       while (curr_fo != NULL) {
           real_ptr = GC_REVEAL_POINTER(curr_fo -> fo_hidden_base);
           GC_MARK_FO(real_ptr, GC_normal_finalize_mark_proc);
           GC_set_mark_bit(real_ptr);
 
-          /* Delete from hash table */
           next_fo = fo_next(curr_fo);
-          if (prev_fo == 0) {
-            GC_fnlz_roots.fo_head[i] = next_fo;
-          } else {
-            fo_set_next(prev_fo, next_fo);
-          }
-          GC_fo_entries--;
 
           /* Add to list of objects awaiting finalization.      */
           fo_set_next(curr_fo, GC_fnlz_roots.finalize_now);
@@ -1125,6 +1118,7 @@ GC_INNER void GC_finalize(void)
           curr_fo = next_fo;
         }
     }
+    GC_fo_entries = 0;  /* all entries deleted from the hash table */
   }
 
   /* Invoke all remaining finalizers that haven't yet been run.