From cf6a1cc5a48717bed67bcb9e32b77e51ea9f53c7 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Sat, 7 May 2022 09:43:54 +0200 Subject: [PATCH] Use the init-statement to declare variables inside the if statement (sonar). --- examples/cpp/clusters-multicpu/s4u-clusters-multicpu.cpp | 3 +-- src/instr/instr_paje_types.cpp | 5 ++--- src/smpi/internals/smpi_memory.cpp | 5 ++--- src/smpi/mpi/smpi_request.cpp | 6 +++--- src/xbt/dynar.cpp | 4 +--- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/examples/cpp/clusters-multicpu/s4u-clusters-multicpu.cpp b/examples/cpp/clusters-multicpu/s4u-clusters-multicpu.cpp index ec75a90c45..8ae7a7a03c 100644 --- a/examples/cpp/clusters-multicpu/s4u-clusters-multicpu.cpp +++ b/examples/cpp/clusters-multicpu/s4u-clusters-multicpu.cpp @@ -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(); diff --git a/src/instr/instr_paje_types.cpp b/src/instr/instr_paje_types.cpp index b3486f70f0..2d7a70f14e 100644 --- a/src/instr/instr_paje_types.cpp +++ b/src/instr/instr_paje_types.cpp @@ -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> 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> platform_variables; + platform_variables.emplace(std::string(resource) + get_name()).second) set_event(now, 0); add_event(now, value); diff --git a/src/smpi/internals/smpi_memory.cpp b/src/smpi/internals/smpi_memory.cpp index 8924bc634d..dab12faeca 100644 --- a/src/smpi/internals/smpi_memory.cpp +++ b/src/smpi/internals/smpi_memory.cpp @@ -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; diff --git a/src/smpi/mpi/smpi_request.cpp b/src/smpi/mpi/smpi_request.cpp index 77e49ab458..e52317b4c3 100644 --- a/src/smpi/mpi/smpi_request.cpp +++ b/src/smpi/mpi/smpi_request.cpp @@ -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()->orecv( - req->real_size(), req->src_host_, dst_host); - if (sleeptime > 0.0) { + if (double sleeptime = simgrid::s4u::Actor::self()->get_host()->extension()->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); } diff --git a/src/xbt/dynar.cpp b/src/xbt/dynar.cpp index 58633d14e4..bc635cab73 100644 --- a/src/xbt/dynar.cpp +++ b/src/xbt/dynar.cpp @@ -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); } -- 2.20.1