Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Fix more implicit casts that should not lower precision (S5276).
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 10 Jul 2020 09:27:15 +0000 (11:27 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 10 Jul 2020 13:11:57 +0000 (15:11 +0200)
16 files changed:
examples/smpi/replay/replay.cpp
src/bindings/lua/lua_host.cpp
src/bindings/lua/lua_platf.cpp
src/bindings/python/simgrid_python.cpp
src/instr/instr_config.cpp
src/instr/instr_platform.cpp
src/instr/instr_resource_utilization.cpp
src/instr/jedule/jedule_platform.cpp
src/kernel/lmm/maxmin.cpp
src/kernel/routing/FatTreeZone.cpp
src/plugins/vm/VmLiveMigration.cpp
src/simdag/sd_dotloader.cpp
src/simdag/sd_task.cpp
src/surf/disk_s19.cpp
src/surf/network_wifi.cpp
src/surf/storage_n11.cpp

index 50b515e..9cb0c63 100644 (file)
@@ -29,7 +29,8 @@ static void overriding_send(simgrid::xbt::ReplayAction& args)
 int main(int argc, char* argv[])
 {
   const char* instance_id = simgrid::s4u::Actor::self()->get_property("instance_id");
-  const int rank          = xbt_str_parse_int(simgrid::s4u::Actor::self()->get_property("rank"), "Cannot parse rank");
+  const int rank =
+      static_cast<int>(xbt_str_parse_int(simgrid::s4u::Actor::self()->get_property("rank"), "Cannot parse rank"));
   const char* trace_filename = argv[1];
   double start_delay_flops   = 0;
 
index 9189731..59361fe 100644 (file)
@@ -101,7 +101,7 @@ static int l_host_number(lua_State * L)
  */
 static int l_host_at(lua_State * L)
 {
-  int index = luaL_checkinteger(L, 1);
+  lua_Integer index            = luaL_checkinteger(L, 1);
   std::vector<sg_host_t> hosts = simgrid::s4u::Engine::get_instance()->get_all_hosts();
   sg_host_t host               = hosts[index - 1]; // lua indexing start by 1 (lua[1] <=> C[0])
   lua_newtable(L);              /* create a table, put the userdata on top of it */
index 9b47ad0..b29dcde 100644 (file)
@@ -179,7 +179,7 @@ int console_add_host(lua_State *L) {
   lua_ensure(type == LUA_TSTRING || type == LUA_TNUMBER,
       "Attribute 'speed' must be specified for host and must either be a string (in the correct format; check documentation) or a number.");
   if (type == LUA_TNUMBER)
-    host.speed_per_pstate.push_back(lua_tointeger(L, -1));
+    host.speed_per_pstate.push_back(lua_tonumber(L, -1));
   else // LUA_TSTRING
     host.speed_per_pstate.push_back(
         xbt_parse_get_speed(ar.short_src, ar.currentline, lua_tostring(L, -1), "speed of host", host.id));
@@ -191,7 +191,7 @@ int console_add_host(lua_State *L) {
   if (not lua_isnumber(L, -1))
     host.core_amount = 1; // Default value
   else
-    host.core_amount = lua_tonumber(L, -1);
+    host.core_amount = static_cast<int>(lua_tointeger(L, -1));
   if (host.core_amount == 0)
     host.core_amount = 1;
   lua_pop(L, 1);
index 1672904..f900c97 100644 (file)
@@ -152,7 +152,7 @@ PYBIND11_MODULE(simgrid, m)
   py::class_<Engine>(m, "Engine", "Simulation Engine")
       .def(py::init([](std::vector<std::string> args) {
         static char noarg[] = {'\0'};
-        int argc            = args.size();
+        int argc            = static_cast<int>(args.size());
         std::unique_ptr<char* []> argv(new char*[argc + 1]);
         for (int i = 0; i != argc; ++i)
           argv[i] = args[i].empty() ? noarg : &args[i].front();
index a0f9afb..f1c9d17 100644 (file)
@@ -172,7 +172,7 @@ static void print_line(const char* option, const char* desc, const char* longdes
 {
   std::string str = std::string("--cfg=") + option + " ";
 
-  int len = str.size();
+  int len = static_cast<int>(str.size());
   XBT_HELP("%s%*.*s %s", str.c_str(), 30 - len, 30 - len, "", desc);
   if (longdesc != nullptr) {
     XBT_HELP("%s\n", longdesc);
index b2d214c..f0f6442 100644 (file)
@@ -53,8 +53,8 @@ static container_t lowestCommonAncestor(const simgrid::instr::Container* a1, con
 
   // find the lowest ancestor
   p     = nullptr;
-  int i = ancestors_a1.size() - 1;
-  int j = ancestors_a2.size() - 1;
+  int i = static_cast<int>(ancestors_a1.size()) - 1;
+  int j = static_cast<int>(ancestors_a2.size()) - 1;
   while (i >= 0 && j >= 0) {
     container_t a1p = ancestors_a1.at(i);
     const simgrid::instr::Container* a2p = ancestors_a2.at(j);
@@ -286,7 +286,8 @@ static void on_netzone_creation(s4u::NetZone const& netzone)
   }
 
   if (TRACE_needs_platform()) {
-    NetZoneContainer* container = new NetZoneContainer(id, currentContainer.size(), currentContainer.back());
+    unsigned level              = static_cast<unsigned>(currentContainer.size());
+    NetZoneContainer* container = new NetZoneContainer(id, level, currentContainer.back());
     currentContainer.push_back(container);
   }
 }
@@ -342,9 +343,9 @@ static void on_host_creation(s4u::Host const& host)
 static void on_action_state_change(kernel::resource::Action const& action,
                                    kernel::resource::Action::State /* previous */)
 {
-  int n = action.get_variable()->get_number_of_constraint();
+  unsigned n = static_cast<unsigned>(action.get_variable()->get_number_of_constraint());
 
-  for (int i = 0; i < n; i++) {
+  for (unsigned i = 0; i < n; i++) {
     double value = action.get_variable()->get_value() * action.get_variable()->get_constraint_weight(i);
     /* Beware of composite actions: ptasks put links and cpus together. Extra pb: we cannot dynamic_cast from void* */
     kernel::resource::Resource* resource = action.get_variable()->get_constraint(i)->get_id();
index 8ab07eb..f67b618 100644 (file)
@@ -16,7 +16,7 @@ void resource_set_utilization(const char* type, const char* name, const char* re
 {
   // only trace resource utilization if resource is known by tracing mechanism
   container_t container = Container::by_name_or_null(resource);
-  if (not container || not value)
+  if (container == nullptr || value == 0.0)
     return;
 
   // trace uncategorized resource utilization
index f9dcd9c..523d5a8 100644 (file)
@@ -69,7 +69,7 @@ int Container::get_child_position(const Container* child) const
 {
   auto it = std::find_if(begin(children_), end(children_),
                          [&child](const std::unique_ptr<Container>& c) { return c.get() == child; });
-  return it == end(children_) ? -1 : std::distance(begin(children_), it);
+  return it == end(children_) ? -1 : static_cast<int>(std::distance(begin(children_), it));
 }
 
 std::vector<int> Container::get_hierarchy()
@@ -96,7 +96,7 @@ std::string Container::get_hierarchy_as_string()
 
   std::vector<int> heir_list = this->get_hierarchy();
 
-  unsigned int length = heir_list.size();
+  unsigned int length = static_cast<unsigned int>(heir_list.size());
   unsigned int i = 0;
   for (auto const& id : heir_list) {
     output += std::to_string(id);
@@ -113,7 +113,7 @@ void Container::print_resources(FILE* jed_file)
   unsigned int i=0;
   xbt_assert(not this->resource_list.empty());
 
-  unsigned int res_nb = this->resource_list.size();
+  unsigned int res_nb = static_cast<unsigned int>(this->resource_list.size());
   std::string resid   = this->get_hierarchy_as_string();
 
   fprintf(jed_file, "      <rset id=\"%s\" nb=\"%u\" names=\"", resid.c_str(), res_nb);
@@ -162,7 +162,7 @@ static void add_subsets_to(std::vector<simgrid::jedule::Subset>& subset_list, st
     unsigned int id             = parent_cont->get_id_by_name(host_name);
     id_list.push_back(id);
   }
-  unsigned int nb_ids = id_list.size();
+  unsigned int nb_ids = static_cast<unsigned int>(id_list.size());
   std::sort(id_list.begin(), id_list.end());
 
   if( nb_ids > 0 ) {
index 7e25ce0..3dd1bb6 100644 (file)
@@ -253,7 +253,7 @@ void System::expand(Constraint* cnst, Variable* var, double consumption_weight)
   elem.constraint         = cnst;
   elem.variable           = var;
 
-  if (var->sharing_penalty_) {
+  if (var->sharing_penalty_ != 0.0) {
     elem.constraint->enabled_element_set_.push_front(elem);
     elem.increase_concurrency();
   } else
@@ -283,7 +283,7 @@ void System::expand_add(Constraint* cnst, Variable* var, double value)
       std::find_if(begin(var->cnsts_), end(var->cnsts_), [&cnst](Element const& x) { return x.constraint == cnst; });
   if (elem_it != end(var->cnsts_)) {
     Element& elem = *elem_it;
-    if (var->sharing_penalty_)
+    if (var->sharing_penalty_ != 0.0)
       elem.decrease_concurrency();
 
     if (cnst->sharing_policy_ != s4u::Link::SharingPolicy::FATPIPE)
@@ -292,7 +292,7 @@ void System::expand_add(Constraint* cnst, Variable* var, double value)
       elem.consumption_weight = std::max(elem.consumption_weight, value);
 
     // We need to check that increasing value of the element does not cross the concurrency limit
-    if (var->sharing_penalty_) {
+    if (var->sharing_penalty_ != 0.0) {
       if (cnst->get_concurrency_slack() < elem.get_concurrency()) {
         double penalty = var->sharing_penalty_;
         disable_var(var);
@@ -939,8 +939,8 @@ double Constraint::get_usage() const
 
 int Constraint::get_variable_amount() const
 {
-  return std::count_if(std::begin(enabled_element_set_), std::end(enabled_element_set_),
-                       [](const Element& elem) { return elem.consumption_weight > 0; });
+  return static_cast<int>(std::count_if(std::begin(enabled_element_set_), std::end(enabled_element_set_),
+                                        [](const Element& elem) { return elem.consumption_weight > 0; }));
 }
 
 } // namespace lmm
index c7ac3d8..ab62664 100644 (file)
@@ -442,7 +442,7 @@ FatTreeNode::FatTreeNode(const ClusterCreationArgs* cluster, int id, int level,
     : id(id), level(level), position(position)
 {
   LinkCreationArgs linkTemplate;
-  if (cluster->limiter_link) {
+  if (cluster->limiter_link != 0.0) {
     linkTemplate.bandwidths.push_back(cluster->limiter_link);
     linkTemplate.latency   = 0;
     linkTemplate.policy    = s4u::Link::SharingPolicy::SHARED;
@@ -450,7 +450,7 @@ FatTreeNode::FatTreeNode(const ClusterCreationArgs* cluster, int id, int level,
     sg_platf_new_link(&linkTemplate);
     this->limiter_link_ = s4u::Link::by_name(linkTemplate.id)->get_impl();
   }
-  if (cluster->loopback_bw || cluster->loopback_lat) {
+  if (cluster->loopback_bw != 0.0 || cluster->loopback_lat != 0.0) {
     linkTemplate.bandwidths.push_back(cluster->loopback_bw);
     linkTemplate.latency   = cluster->loopback_lat;
     linkTemplate.policy    = s4u::Link::SharingPolicy::FATPIPE;
index c047a12..0712e95 100644 (file)
@@ -115,7 +115,7 @@ sg_size_t MigrationTx::sendMigrationData(sg_size_t size, int stage, int stage2_r
 
   double clock_end    = s4u::Engine::get_clock();
   double duration     = clock_end - clock_sta;
-  double actual_speed = size / duration;
+  double actual_speed = static_cast<double>(size) / duration;
 
   if (stage == 2)
     XBT_DEBUG("mig-stage%d.%d: sent %llu duration %f actual_speed %f (target %f)", stage, stage2_round, size, duration,
@@ -134,7 +134,7 @@ void MigrationTx::operator()()
   double host_speed       = vm_->get_pm()->get_speed();
   const sg_size_t ramsize = vm_->get_ramsize();
   const double dp_rate =
-      host_speed ? (sg_vm_get_migration_speed(vm_) * sg_vm_get_dirty_page_intensity(vm_)) / host_speed : 1;
+      host_speed != 0.0 ? (sg_vm_get_migration_speed(vm_) * sg_vm_get_dirty_page_intensity(vm_)) / host_speed : 1;
   const sg_size_t dp_cap = sg_vm_get_working_set_memory(vm_);
   const double mig_speed = sg_vm_get_migration_speed(vm_);
   double max_downtime    = sg_vm_get_max_downtime(vm_);
index 39792bb..d9aaeaf 100644 (file)
@@ -213,7 +213,7 @@ xbt_dynar_t SD_dotload_generic(const char* filename, bool sequential, bool sched
             if (previous_task && not SD_task_dependency_exists(previous_task, cur_task))
               SD_task_dependency_add(previous_task, cur_task);
 
-            SD_task_schedulel(cur_task, 1, hosts[std::stod(elm.first)]);
+            SD_task_schedulel(cur_task, 1, hosts[std::stoi(elm.first)]);
             previous_task = cur_task;
           }
         }
index ec33841..05a3afc 100644 (file)
@@ -371,7 +371,7 @@ xbt_dynar_t SD_task_get_children(const_SD_task_t task)
  */
 int SD_task_get_workstation_count(const_SD_task_t task)
 {
-  return task->allocation->size();
+  return static_cast<int>(task->allocation->size());
 }
 
 /**
@@ -591,10 +591,10 @@ int SD_task_dependency_exists(const_SD_task_t src, SD_task_t dst)
     if (dst) {
       return (src->successors->find(dst) != src->successors->end() || src->outputs->find(dst) != src->outputs->end());
     } else {
-      return src->successors->size() + src->outputs->size();
+      return static_cast<int>(src->successors->size() + src->outputs->size());
     }
   } else {
-    return dst->predecessors->size() + dst->inputs->size();
+    return static_cast<int>(dst->predecessors->size() + dst->inputs->size());
   }
 }
 
@@ -916,7 +916,7 @@ void SD_task_schedulev(SD_task_t task, int count, const sg_host_t * list)
 
   /* Iterate over all inputs and outputs to say where I am located (and start them if runnable) */
   for (auto const& input : *task->inputs) {
-    int src_nb = input->allocation->size();
+    int src_nb = static_cast<int>(input->allocation->size());
     int dst_nb = count;
     if (input->allocation->empty())
       XBT_VERB("Sender side of '%s' not scheduled. Set receiver side to '%s''s allocation", input->name, task->name);
@@ -936,7 +936,7 @@ void SD_task_schedulev(SD_task_t task, int count, const sg_host_t * list)
 
   for (auto const& output : *task->outputs) {
     int src_nb = count;
-    int dst_nb = output->allocation->size();
+    int dst_nb = static_cast<int>(output->allocation->size());
     if (output->allocation->empty())
       XBT_VERB("Receiver side of '%s' not scheduled. Set sender side to '%s''s allocation", output->name, task->name);
 
index 66525d7..0f3f4b7 100644 (file)
@@ -48,7 +48,7 @@ void DiskS19Model::update_actions_state(double /*now*/, double delta)
   for (auto it = std::begin(*get_started_action_set()); it != std::end(*get_started_action_set());) {
     auto& action = *it;
     ++it; // increment iterator here since the following calls to action.finish() may invalidate it
-    action.update_remains(lrint(action.get_variable()->get_value() * delta));
+    action.update_remains(rint(action.get_variable()->get_value() * delta));
     action.update_max_duration(delta);
 
     if (((action.get_remains_no_update() <= 0) && (action.get_variable()->get_penalty() > 0)) ||
@@ -70,17 +70,17 @@ DiskS19::DiskS19(DiskModel* model, const std::string& name, lmm::System* maxminS
 
 DiskAction* DiskS19::io_start(sg_size_t size, s4u::Io::OpType type)
 {
-  return new DiskS19Action(get_model(), size, not is_on(), this, type);
+  return new DiskS19Action(get_model(), static_cast<double>(size), not is_on(), this, type);
 }
 
 DiskAction* DiskS19::read(sg_size_t size)
 {
-  return new DiskS19Action(get_model(), size, not is_on(), this, s4u::Io::OpType::READ);
+  return new DiskS19Action(get_model(), static_cast<double>(size), not is_on(), this, s4u::Io::OpType::READ);
 }
 
 DiskAction* DiskS19::write(sg_size_t size)
 {
-  return new DiskS19Action(get_model(), size, not is_on(), this, s4u::Io::OpType::WRITE);
+  return new DiskS19Action(get_model(), static_cast<double>(size), not is_on(), this, s4u::Io::OpType::WRITE);
 }
 
 /**********
index 6d90be5..9c60524 100644 (file)
@@ -64,8 +64,8 @@ s4u::Link::SharingPolicy NetworkWifiLink::get_sharing_policy()
 
 void NetworkWifiLink::refresh_decay_bandwidths(){
   // Compute number of STAtion on the Access Point
-  int nSTA=host_rates_.size();
-    
+  int nSTA = static_cast<int>(host_rates_.size());
+
   std::vector<Metric> new_bandwidths;
   for (auto bandwidth : bandwidths_){
     // Instantiate decay model relatively to the actual bandwidth
index cc116c5..dba05a8 100644 (file)
@@ -78,7 +78,7 @@ void StorageN11Model::update_actions_state(double /*now*/, double delta)
   for (auto it = std::begin(*get_started_action_set()); it != std::end(*get_started_action_set());) {
     auto& action = *it;
     ++it; // increment iterator here since the following calls to action.finish() may invalidate it
-    action.update_remains(lrint(action.get_variable()->get_value() * delta));
+    action.update_remains(rint(action.get_variable()->get_value() * delta));
     action.update_max_duration(delta);
 
     if (((action.get_remains_no_update() <= 0) && (action.get_variable()->get_penalty() > 0)) ||
@@ -103,17 +103,17 @@ StorageN11::StorageN11(StorageModel* model, const std::string& name, lmm::System
 
 StorageAction* StorageN11::io_start(sg_size_t size, s4u::Io::OpType type)
 {
-  return new StorageN11Action(get_model(), size, not is_on(), this, type);
+  return new StorageN11Action(get_model(), static_cast<double>(size), not is_on(), this, type);
 }
 
 StorageAction* StorageN11::read(sg_size_t size)
 {
-  return new StorageN11Action(get_model(), size, not is_on(), this, s4u::Io::OpType::READ);
+  return new StorageN11Action(get_model(), static_cast<double>(size), not is_on(), this, s4u::Io::OpType::READ);
 }
 
 StorageAction* StorageN11::write(sg_size_t size)
 {
-  return new StorageN11Action(get_model(), size, not is_on(), this, s4u::Io::OpType::WRITE);
+  return new StorageN11Action(get_model(), static_cast<double>(size), not is_on(), this, s4u::Io::OpType::WRITE);
 }
 
 /**********