Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Avoid buffer overflow.
[simgrid.git] / src / simdag / sd_global.cpp
index 80a61055826b719ec2ad74e803a1d2e82b448887..e8ba4ed07dbbea69d4abac7d2f98294390e4476f 100644 (file)
@@ -10,6 +10,8 @@
 #include "simgrid/sg_config.hpp"
 #include "src/surf/surf_interface.hpp"
 
+#include <array>
+
 XBT_LOG_NEW_CATEGORY(sd, "Logging specific to SimDag");
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_kernel, sd, "Logging specific to SimDag (kernel)");
 
@@ -124,9 +126,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 constexpr 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))));
 }
 
 /**