From c6b98b47d12d799b9da4232012268f39ea424daa Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Sat, 17 Apr 2021 00:11:41 +0200 Subject: [PATCH] A for-loop with 'num' modified in the body is too complex according to Sonar. --- src/smpi/mpi/smpi_topo.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/smpi/mpi/smpi_topo.cpp b/src/smpi/mpi/smpi_topo.cpp index 14e819fc26..5f28d6fc49 100644 --- a/src/smpi/mpi/smpi_topo.cpp +++ b/src/smpi/mpi/smpi_topo.cpp @@ -383,11 +383,13 @@ static int getfactors(int num, std::vector& 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) { -- 2.20.1