Fix 'scope of var can be reduced' cppcheck warnings in check_heap_stats
authorIvan Maidanski <ivmai@mail.ru>
Fri, 8 Jun 2018 20:21:38 +0000 (23:21 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Fri, 8 Jun 2018 20:23:21 +0000 (23:23 +0300)
(fix of commit 4e909d2)

Also, print the message about the leak-find mode just once per gctest
execution.

* tests/test.c (INIT_FIND_LEAK): Define macro.
* tests/test.c (GC_COND_INIT): Invoke INIT_FIND_LEAK.
* tests/test.c (run_one_test): Remove print about leak-find mode.
* tests/test.c [!GC_NO_FINALIZATION] (check_heap_stats): Move
still_live and still_long_live local variables to the block of their
usage.

tests/test.c

index 2a1aa3d..f632957 100644 (file)
 #  define GC_OPT_INIT /* empty */
 #endif
 
+#define INIT_FIND_LEAK \
+    if (!GC_get_find_leak()) {} else \
+      GC_printf("This test program is not designed for leak detection mode\n")
+
 #ifdef NO_CLOCK
 # define INIT_PERF_MEASUREMENT (void)0
 #else
 
 #define GC_COND_INIT() \
     INIT_FORK_SUPPORT; GC_OPT_INIT; CHECK_GCLIB_VERSION; \
-    INIT_PRINT_STATS; INIT_PERF_MEASUREMENT
+    INIT_PRINT_STATS; INIT_FIND_LEAK; INIT_PERF_MEASUREMENT
 
 #define CHECK_OUT_OF_MEMORY(p) \
             if ((p) == NULL) { \
@@ -1285,10 +1289,6 @@ void run_one_test(void)
       int wstatus;
 #   endif
 
-    if (GC_get_find_leak())
-        GC_printf(
-              "This test program is not designed for leak detection mode\n"
-              "Expect lots of problems\n");
     GC_FREE(0);
 #   ifdef THREADS
       if (!GC_thread_is_registered()) {
@@ -1581,10 +1581,6 @@ void check_heap_stats(void)
     size_t max_heap_sz;
     int i;
 #   ifndef GC_NO_FINALIZATION
-      int still_live;
-#     ifndef GC_LONG_REFS_NOT_NEEDED
-        int still_long_live = 0;
-#     endif
 #     ifdef FINALIZE_ON_DEMAND
         int late_finalize_count = 0;
 #     endif
@@ -1669,6 +1665,11 @@ void check_heap_stats(void)
                   finalized_count, finalizable_count);
 # ifndef GC_NO_FINALIZATION
     if (!GC_get_find_leak()) {
+      int still_live = 0;
+#     ifndef GC_LONG_REFS_NOT_NEEDED
+        int still_long_live = 0;
+#     endif
+
 #     ifdef FINALIZE_ON_DEMAND
         if (finalized_count != late_finalize_count) {
             GC_printf("Demand finalization error\n");
@@ -1682,7 +1683,6 @@ void check_heap_stats(void)
       } else {
         GC_printf("finalization is probably ok\n");
       }
-      still_live = 0;
       for (i = 0; i < MAX_FINALIZED; i++) {
         if (live_indicators[i] != 0) {
             still_live++;