Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Don't modify condition variable twice in for loops.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 26 Feb 2020 22:03:57 +0000 (23:03 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 26 Feb 2020 22:03:57 +0000 (23:03 +0100)
src/xbt/xbt_log_layout_format.cpp
teshsuite/surf/maxmin_bench/maxmin_bench.cpp

index 6f488e4..e07eca4 100644 (file)
@@ -75,7 +75,8 @@ static int xbt_log_layout_format_doit(const s_xbt_log_layout_t* l, xbt_log_event
   int precision = -1;
   int length = -1;
 
-  for (char* q = static_cast<char*>(l->data) ; *q != '\0' ; q++) {
+  char* q = static_cast<char*>(l->data);
+  while (*q != '\0') {
     if (*q == '%') {
       q++;
       do {
@@ -169,6 +170,7 @@ static int xbt_log_layout_format_doit(const s_xbt_log_layout_t* l, xbt_log_event
       *p = *q;
       check_overflow(1);
     }
+    q++;
   }
   *p = '\0';
 
index 9e95082..e2d1d9f 100644 (file)
@@ -50,11 +50,10 @@ static void test(int nb_cnst, int nb_var, int nb_elem, unsigned int pw_base_limi
     for (int j = 0; j < nb_cnst; j++)
       used[j] = 0;
     for (int j = 0; j < nb_elem; j++) {
-      int k = simgrid::xbt::random::uniform_int(0, nb_cnst - 1);
-      if (used[k]>=concurrency_share) {
-        j--;
-        continue;
-      }
+      int k;
+      do {
+        k = simgrid::xbt::random::uniform_int(0, nb_cnst - 1);
+      } while (used[k] >= concurrency_share);
       Sys->expand(cnst[k], var[i], simgrid::xbt::random::uniform_real(0.0, 1.5));
       Sys->expand_add(cnst[k], var[i], simgrid::xbt::random::uniform_real(0.0, 1.5));
       used[k]++;