]> granicus.if.org Git - libatomic_ops/commitdiff
Eliminate 'casting signed to bigger unsigned int' CSA warning (test_stack)
authorIvan Maidanski <ivmai@mail.ru>
Sat, 10 Nov 2018 06:24:16 +0000 (09:24 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Sat, 10 Nov 2018 06:24:16 +0000 (09:24 +0300)
* tests/test_stack.c (run_one_test): Change type of index, i local
variables from int to unsigned.
* tests/test_stack.c [VERBOSE] (run_one_test): Change type of j local
variable from int to unsigned; update print format specifier
accordingly.
* tests/test_stack.c (main): Change type of i local variable from int
to unsigned.

tests/test_stack.c

index 4edc88bb6d90bbb7a05bdea6362d709b7cdb93a4..b42a0057db25a09688235274a927f4ff90a3ab7a 100644 (file)
@@ -179,16 +179,16 @@ volatile AO_t ops_performed = 0;
 #endif
 {
   list_element * t[MAX_NTHREADS + 1];
-  int index = (int)(size_t)arg;
-  int i;
+  unsigned index = (unsigned)(size_t)arg;
+  unsigned i;
 # ifdef VERBOSE
-    int j = 0;
+    unsigned j = 0;
 
-    printf("starting thread %d\n", index);
+    printf("starting thread %u\n", index);
 # endif
   while (fetch_and_add(&ops_performed, index + 1) + index + 1 < LIMIT)
     {
-      for (i = 0; i < index + 1; ++i)
+      for (i = 0; i <= index; ++i)
         {
           t[i] = (list_element *)AO_stack_pop(&the_list);
           if (0 == t[i])
@@ -197,7 +197,7 @@ volatile AO_t ops_performed = 0;
               abort();
             }
         }
-      for (i = 0; i < index + 1; ++i)
+      for (i = 0; i <= index; ++i)
         {
           AO_stack_push(&the_list, (AO_t *)t[i]);
         }
@@ -206,7 +206,7 @@ volatile AO_t ops_performed = 0;
 #     endif
     }
 # ifdef VERBOSE
-    printf("finished thread %d: %d total ops\n", index, j);
+    printf("finished thread %u: %u total ops\n", index, j);
 # endif
   return 0;
 }
@@ -245,7 +245,7 @@ int main(int argc, char **argv)
   for (exper_n = 0; exper_n < N_EXPERIMENTS; ++ exper_n)
     for (nthreads = 1; nthreads <= max_nthreads; ++nthreads)
       {
-        int i;
+        unsigned i;
 #       ifdef USE_WINTHREADS
           DWORD thread_id;
           HANDLE thread[MAX_NTHREADS];
@@ -268,7 +268,7 @@ int main(int argc, char **argv)
 #       endif
         ops_performed = 0;
         start_time = get_msecs();
-        for (i = 1; i < nthreads; ++i) {
+        for (i = 1; (int)i < nthreads; ++i) {
           int code;
 
 #         ifdef USE_WINTHREADS
@@ -287,7 +287,7 @@ int main(int argc, char **argv)
         /* We use the main thread to run one test.  This allows gprof   */
         /* profiling to work, for example.                              */
         run_one_test(0);
-        for (i = 1; i < nthreads; ++i) {
+        for (i = 1; (int)i < nthreads; ++i) {
           int code;
 
 #         ifdef USE_WINTHREADS