Workaround 'duplicate expression for condition and assignment' cppcheck FP
authorIvan Maidanski <ivmai@mail.ru>
Tue, 23 Apr 2019 19:21:54 +0000 (22:21 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 23 Apr 2019 19:21:54 +0000 (22:21 +0300)
The entitled cppcheck warnings are false positives.

* alloc.c (GC_should_collect): Move reassignment of the global variable
which is checked in the conditional expression to the end of the
conditional block statement.
* finalize.c (GC_notify_or_invoke_finalizers): Likewise.
* mark.c [WRAP_MARK_SOME] (GC_mark_some): Likewise.

alloc.c
finalize.c
mark.c

diff --git a/alloc.c b/alloc.c
index a0c2a1c..45fd086 100644 (file)
--- a/alloc.c
+++ b/alloc.c
@@ -388,8 +388,8 @@ GC_INNER GC_bool GC_should_collect(void)
     static word last_min_bytes_allocd;
     static word last_gc_no;
     if (last_gc_no != GC_gc_no) {
-      last_gc_no = GC_gc_no;
       last_min_bytes_allocd = min_bytes_allocd();
+      last_gc_no = GC_gc_no;
     }
     return(GC_adj_bytes_allocd() >= last_min_bytes_allocd
            || GC_heapsize >= GC_collect_at_heapsize);
index d01c2aa..5c23b4c 100644 (file)
@@ -1368,8 +1368,8 @@ GC_INNER void GC_notify_or_invoke_finalizers(void)
 
     /* These variables require synchronization to avoid data races.     */
     if (last_finalizer_notification != GC_gc_no) {
-        last_finalizer_notification = GC_gc_no;
         notifier_fn = GC_finalizer_notifier;
+        last_finalizer_notification = GC_gc_no;
     }
     UNLOCK();
     if (notifier_fn != 0)
diff --git a/mark.c b/mark.c
index 77e9dbb..6aed170 100644 (file)
--- a/mark.c
+++ b/mark.c
@@ -564,9 +564,9 @@ handle_ex:
 
         /* Warn about it at most once per collection. */
         if (warned_gc_no != GC_gc_no) {
-          warned_gc_no = GC_gc_no;
           WARN("Caught ACCESS_VIOLATION in marker;"
                " memory mapping disappeared\n", 0);
+          warned_gc_no = GC_gc_no;
         }
       }
       /* We have bad roots on the stack.  Discard mark stack.   */