Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use the init-statement to declare variables inside the if statement (sonar).
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 7 May 2022 07:43:54 +0000 (09:43 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 9 May 2022 13:11:42 +0000 (15:11 +0200)
examples/cpp/clusters-multicpu/s4u-clusters-multicpu.cpp
src/instr/instr_paje_types.cpp
src/smpi/internals/smpi_memory.cpp
src/smpi/mpi/smpi_request.cpp
src/xbt/dynar.cpp

index ec75a90..8ae7a7a 100644 (file)
@@ -293,10 +293,9 @@ static void create_dragonfly_cluster()
 int main(int argc, char* argv[])
 {
   sg4::Engine e(&argc, argv);
-  std::string platform = argv[1];
 
   /* create platform */
-  if (platform == "torus")
+  if (std::string platform(argv[1]); platform == "torus")
     create_torus_cluster();
   else if (platform == "fatTree")
     create_fatTree_cluster();
index b3486f7..2d7a70f 100644 (file)
@@ -66,11 +66,10 @@ void VariableType::instr_event(double now, double delta, const char* resource, d
    */
 
   // to check if variables were previously set to 0, otherwise paje won't simulate them
-  static std::set<std::string, std::less<>> platform_variables;
-
   // create a key considering the resource and variable, and check if key exists in the global map:
   // if it doesn't, set the variable to zero.
-  if (platform_variables.emplace(std::string(resource) + get_name()).second)
+  if (static std::set<std::string, std::less<>> platform_variables;
+      platform_variables.emplace(std::string(resource) + get_name()).second)
     set_event(now, 0);
 
   add_event(now, value);
index 8924bc6..dab12fa 100644 (file)
@@ -71,9 +71,8 @@ static void smpi_get_executable_global_size()
       /* Here we are making the assumption that a suitable empty region
          following the rw- area is the end of the data segment. It would
          be better to check with the size of the data segment. */
-      auto j = i + 1;
-      if (j != map.end() && j->pathname.empty() && (j->prot & PROT_RWX) == PROT_RW &&
-          (char*)j->start_addr == smpi_data_exe_start + smpi_data_exe_size) {
+      if (auto j = i + 1; j != map.end() && j->pathname.empty() && (j->prot & PROT_RWX) == PROT_RW &&
+                          (char*)j->start_addr == smpi_data_exe_start + smpi_data_exe_size) {
         // Only count the portion of this region not present in the initial map.
         auto found    = std::find_if(initial_vm_map.begin(), initial_vm_map.end(), [&j](const simgrid::xbt::VmMap& m) {
           return j->start_addr <= m.start_addr && m.start_addr < j->end_addr;
index 77e49ab..e52317b 100644 (file)
@@ -1025,9 +1025,9 @@ void Request::finish_wait(MPI_Request* request, MPI_Status * status)
   if(req->detached_sender_ != nullptr){
     //integrate pseudo-timing for buffering of small messages, do not bother to execute the simcall if 0
     simgrid::s4u::Host* dst_host = simgrid::s4u::Actor::by_pid(req->dst_)->get_host();
-    double sleeptime             = simgrid::s4u::Actor::self()->get_host()->extension<simgrid::smpi::Host>()->orecv(
-        req->real_size(), req->src_host_, dst_host);
-    if (sleeptime > 0.0) {
+    if (double sleeptime = simgrid::s4u::Actor::self()->get_host()->extension<simgrid::smpi::Host>()->orecv(
+            req->real_size(), req->src_host_, dst_host);
+        sleeptime > 0.0) {
       simgrid::s4u::this_actor::sleep_for(sleeptime);
       XBT_DEBUG("receiving size of %zu : sleep %f ", req->real_size_, sleeptime);
     }
index 58633d1..bc635ca 100644 (file)
@@ -240,9 +240,7 @@ void xbt_dynar_remove_at(xbt_dynar_t dynar, int idx, void* object)
     dynar->free_f(_xbt_dynar_elm(dynar, idx));
   }
 
-  unsigned long nb_shift = dynar->used - 1 - idx;
-
-  if (nb_shift) {
+  if (unsigned long nb_shift = dynar->used - 1 - idx; nb_shift > 0) {
     unsigned long offset = nb_shift * dynar->elmsize;
     memmove(_xbt_dynar_elm(dynar, idx), _xbt_dynar_elm(dynar, idx + 1), offset);
   }