Blob Blame History Raw
From 658d0711f76ed015aafa2f50604d9ff74e79d28c Mon Sep 17 00:00:00 2001
From: Ivan Maidanski <ivmai@mail.ru>
Date: Fri, 13 Jun 2014 16:35:55 +0400
Subject: [PATCH 06/20] Eliminate 'variable set but not used' Cppcheck warnings
 in test_stack

* tests/test_stack.c (run_one_test): Define "j" local variable only
if VERBOSE.
* tests/test_stack.c (main): Do not define "sum" local variable (and
don not compute the sum) if NO_TIMES.
---
 tests/test_stack.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/tests/test_stack.c b/tests/test_stack.c
index 8170e5c..a3c5c30 100644
--- a/tests/test_stack.c
+++ b/tests/test_stack.c
@@ -175,9 +175,9 @@ volatile AO_t ops_performed = 0;
   list_element * t[MAX_NTHREADS + 1];
   int index = (int)(size_t)arg;
   int i;
-  int j = 0;
-
 # ifdef VERBOSE
+    int j = 0;
+
     printf("starting thread %d\n", index);
 # endif
   while (fetch_and_add(&ops_performed, index + 1) + index + 1 < LIMIT)
@@ -195,7 +195,9 @@ volatile AO_t ops_performed = 0;
         {
           AO_stack_push(&the_list, (AO_t *)t[i]);
         }
-      j += (index + 1);
+#     ifdef VERBOSE
+        j += index + 1;
+#     endif
     }
 # ifdef VERBOSE
     printf("finished thread %d: %d total ops\n", index, j);
@@ -303,22 +305,23 @@ int main(int argc, char **argv)
       }
     for (nthreads = 1; nthreads <= max_nthreads; ++nthreads)
       {
-        unsigned long sum = 0;
+#       ifndef NO_TIMES
+          unsigned long sum = 0;
+#       endif
 
         printf("About %d pushes + %d pops in %d threads:",
                LIMIT, LIMIT, nthreads);
-        for (exper_n = 0; exper_n < N_EXPERIMENTS; ++exper_n)
-          {
+#       ifndef NO_TIMES
+          for (exper_n = 0; exper_n < N_EXPERIMENTS; ++exper_n) {
 #           if defined(VERBOSE)
               printf(" [%lu]", times[nthreads][exper_n]);
 #           endif
             sum += times[nthreads][exper_n];
           }
-#     ifndef NO_TIMES
-        printf(" %lu msecs\n", (sum + N_EXPERIMENTS/2)/N_EXPERIMENTS);
-#     else
-        printf(" completed\n");
-#     endif
+          printf(" %lu msecs\n", (sum + N_EXPERIMENTS/2)/N_EXPERIMENTS);
+#       else
+          printf(" completed\n");
+#       endif
       }
   return 0;
 }
-- 
1.9.3