Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Replace some C-style arrays.
[simgrid.git] / src / simdag / sd_global.cpp
index 54c0aeb..22d4faf 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006-2019. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2006-2020. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -44,7 +44,7 @@ std::set<SD_task_t>* simulate(double how_long){
     for (auto const& model : all_existing_models) {
       const simgrid::kernel::resource::Action* action = model->extract_done_action();
       while (action != nullptr && action->get_data() != nullptr) {
-        SD_task_t task = static_cast<SD_task_t>(action->get_data());
+        auto* task = static_cast<SD_task_t>(action->get_data());
         XBT_VERB("Task '%s' done", SD_task_get_name(task));
         SD_task_set_state(task, SD_DONE);
 
@@ -94,7 +94,7 @@ std::set<SD_task_t>* simulate(double how_long){
       /* let's see which tasks have just failed */
       action = model->extract_failed_action();
       while (action != nullptr) {
-        SD_task_t task = static_cast<SD_task_t>(action->get_data());
+        auto* task = static_cast<SD_task_t>(action->get_data());
         XBT_VERB("Task '%s' failed", SD_task_get_name(task));
         SD_task_set_state(task, SD_FAILED);
         sd_global->return_set.insert(task);
@@ -124,9 +124,9 @@ std::set<SD_task_t>* simulate(double how_long){
  * @return the equivalent as a readable string
  */
 const char *__get_state_name(e_SD_task_state_t state){
-  static std::string state_names[7] =
-    { "not scheduled", "schedulable", "scheduled", "runnable","running", "done", "failed" };
-  return state_names[static_cast<int>(log2(static_cast<double>(state)))].data();
+  static std::array<const char*, 7> state_names{
+      {"not scheduled", "schedulable", "scheduled", "runnable", "running", "done", "failed"}};
+  return state_names.at(static_cast<int>(log2(static_cast<double>(state))));
 }
 
 /**