From 8568ff0dcd9ce59bd6f6b1a8b0cd33a4cc36f325 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 8 Jun 2018 23:21:38 +0300 Subject: [PATCH] Fix 'scope of var can be reduced' cppcheck warnings in check_heap_stats (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 | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/test.c b/tests/test.c index 2a1aa3d7..f6329575 100644 --- a/tests/test.c +++ b/tests/test.c @@ -159,6 +159,10 @@ # 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 @@ -167,7 +171,7 @@ #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++; -- 2.40.0