Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
A for-loop with 'num' modified in the body is too complex according to Sonar.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 16 Apr 2021 22:11:41 +0000 (00:11 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 16 Apr 2021 22:20:57 +0000 (00:20 +0200)
src/smpi/mpi/smpi_topo.cpp

index 14e819f..5f28d6f 100644 (file)
@@ -383,11 +383,13 @@ static int getfactors(int num, std::vector<int>& factors)
     factors.push_back(2);
   }
   /* determine all occurrences of uneven prime numbers up to sqrt(num) */
-  for (int d = 3; (num > 1) && (d * d < num); d += 2) {
+  int d = 3;
+  while ((num > 1) && (d * d < num)) {
     while((num % d) == 0) {
       num /= d;
       factors.push_back(d);
     }
+    d += 2;
   }
   /* as we looped only up to sqrt(num) one factor > sqrt(num) may be left over */
   if(num != 1) {