Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill some more atof
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 7 Feb 2016 17:38:22 +0000 (18:38 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 7 Feb 2016 17:38:22 +0000 (18:38 +0100)
examples/msg/bittorrent/tracker.c
examples/msg/icomms/peer.c
examples/msg/icomms/peer3.c
examples/msg/semaphores/synchro.c
src/surf/network_ib.cpp
src/surf/plugins/energy.cpp
src/surf/sg_platf.cpp
src/surf/surf_routing.cpp
teshsuite/msg/trace/test_trace_integration.c

index 15f6a94..72ff0d1 100644 (file)
@@ -24,7 +24,7 @@ int tracker(int argc, char *argv[])
   //Checking arguments
   xbt_assert(argc == 2, "Wrong number of arguments for the tracker.");
   //Retrieving end time
-  double deadline = atof(argv[1]);
+  double deadline = xbt_str_parse_double(argv[1],"Invalid deadline: %s");
   xbt_assert(deadline > 0, "Wrong deadline supplied");
   //Building peers array
   xbt_dynar_t peers_list = xbt_dynar_new(sizeof(int), NULL);
index 77e6058..1e322b4 100644 (file)
@@ -101,8 +101,8 @@ int receiver(int argc, char *argv[])
   int id = -1;
   char mailbox[80];
   msg_comm_t res_irecv;
-  double sleep_start_time = atof(argv[2]);
-  double sleep_test_time = atof(argv[3]);
+  double sleep_start_time = xbt_str_parse_double(argv[2], "Invalid sleep start parameter: %s");
+  double sleep_test_time = xbt_str_parse_double(argv[3], "Invalid sleep test parameter: %s");
   XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time,
         sleep_test_time);
 
index 22072b4..a0fe6c6 100644 (file)
@@ -90,7 +90,7 @@ int receiver(int argc, char *argv[])
   int i;
   char mailbox[80];
   xbt_dynar_t comms = xbt_dynar_new(sizeof(msg_comm_t), NULL);
-  int tasks = atof(argv[2]);
+  int tasks = xbt_str_parse_int(argv[2], "Invalid amount of tasks: %s");
   msg_task_t *task = xbt_new(msg_task_t, tasks);
 
   XBT_ATTRIB_UNUSED int read;
index f64e726..5919698 100644 (file)
@@ -19,13 +19,13 @@ static int peer(int argc, char* argv[]){
   int i = 0; 
   
   while(i < argc) {
-    double wait_time = atof(argv[i++]);
+    double wait_time = xbt_str_parse_double(argv[i++],"Invalid wait time: %s");
     MSG_process_sleep(wait_time);
     XBT_INFO("Trying to acquire %d", i);
     MSG_sem_acquire(sem);
     XBT_INFO("Acquired %d", i);
 
-    wait_time = atof(argv[i++]);
+    wait_time = xbt_str_parse_double(argv[i++], "Invalid wait time: %s");
     MSG_process_sleep(wait_time);
     XBT_INFO("Releasing %d", i);
     MSG_sem_release(sem);
index 5ddb5e2..8c64c0c 100644 (file)
@@ -118,9 +118,9 @@ NetworkIBModel::NetworkIBModel()
   if(xbt_dynar_length(radical_elements)!=3)
     surf_parse_error("smpi/IB_penalty_factors should be provided and contain 3 elements, semi-colon separated : for example 0.965;0.925;1.35");
   
-  Be = atof(xbt_dynar_get_as(radical_elements, 0, char *));
-  Bs = atof(xbt_dynar_get_as(radical_elements, 1, char *));
-  ys = atof(xbt_dynar_get_as(radical_elements, 2, char *));
+  Be = xbt_str_parse_double(xbt_dynar_get_as(radical_elements, 0, char *), "First part of smpi/IB_penalty_factors is not numerical: %s");
+  Bs = xbt_str_parse_double(xbt_dynar_get_as(radical_elements, 1, char *), "Second part of smpi/IB_penalty_factors is not numerical: %s");
+  ys = xbt_str_parse_double(xbt_dynar_get_as(radical_elements, 2, char *), "Third part of smpi/IB_penalty_factors is not numerical: %s");
 
   xbt_dynar_free(&radical_elements);
 }
index 451dd83..c7ad3f8 100644 (file)
@@ -103,10 +103,10 @@ HostEnergy::HostEnergy(simgrid::s4u::Host *ptr) :
   initWattsRangeList();
 
   if (host->properties() != NULL) {
-    char* off_power_str = (char*)xbt_dict_get_or_null(
-      host->properties(), "watt_off");
+    char* off_power_str = (char*)xbt_dict_get_or_null(host->properties(), "watt_off");
     if (off_power_str != NULL)
-      watts_off = atof(off_power_str);
+      watts_off = xbt_str_parse_double(off_power_str,
+          bprintf("Invalid value for property watt_off of host %s: %%s",host->name().c_str()));
     else
       watts_off = 0;
   }
@@ -183,8 +183,10 @@ void HostEnergy::initWattsRangeList()
     /* min_power corresponds to the idle power (cpu load = 0) */
     /* max_power is the power consumed at 100% cpu load       */
     power_range_watts_list.push_back(power_range(
-      atof(xbt_dynar_get_as(current_power_values, 0, char*)),
-      atof(xbt_dynar_get_as(current_power_values, 1, char*))
+      xbt_str_parse_double(xbt_dynar_get_as(current_power_values, 0, char*),
+          bprintf("Invalid min value for pstate %d on host %s: %%s", i, host->name().c_str())),
+      xbt_str_parse_double(xbt_dynar_get_as(current_power_values, 1, char*),
+          bprintf("Invalid min value for pstate %d on host %s: %%s", i, host->name().c_str()))
     ));
 
     xbt_dynar_free(&current_power_values);
index be25920..62c6115 100644 (file)
@@ -108,7 +108,7 @@ void sg_platf_new_router(sg_platf_router_cbarg_t router)
     xbt_dynar_t ctn_str = xbt_str_split_str(router->coord, " ");
     xbt_dynar_t ctn = xbt_dynar_new(sizeof(double),NULL);
     xbt_dynar_foreach(ctn_str,cursor, str) {
-      double val = atof(str);
+      double val = xbt_str_parse_double(str, "Invalid coordinate: %s");
       xbt_dynar_push(ctn,&val);
     }
     xbt_dynar_shrink(ctn, 0);
index afb17ba..96ec550 100644 (file)
@@ -188,7 +188,7 @@ simgrid::surf::NetCard *routing_add_host(
     xbt_dynar_t ctn_str = xbt_str_split_str(host->coord, " ");
     xbt_dynar_t ctn = xbt_dynar_new(sizeof(double),NULL);
     xbt_dynar_foreach(ctn_str,cursor, str) {
-      double val = atof(str);
+      double val = xbt_str_parse_double(str, "Invalid coordinate: %s");
       xbt_dynar_push(ctn,&val);
     }
     xbt_dynar_shrink(ctn, 0);
index ff5292c..d0f52cf 100644 (file)
@@ -22,14 +22,10 @@ int test_trace(int argc, char *argv[])
   double task_comp_size = 2800;
   double task_prio = 1.0;
 
-  if (argc != 3) {
-    printf
-        ("Wrong number of arguments!\nUsage:\n\t1) task computational size in FLOPS\n\t2 task priority\n");
-    exit(1);
-  }
+  xbt_assert (argc == 3,"Wrong number of arguments!\nUsage: %s <task computational size in FLOPS> <task priority>", argv[0]);
 
-  task_comp_size = atof(argv[1]);
-  task_prio = atof(argv[2]);
+  task_comp_size = xbt_str_parse_double(argv[1],"Invalid computational size: %s");
+  task_prio = xbt_str_parse_double(argv[2], "Invalid task priority: %s");
 
   XBT_INFO("Testing the trace integration cpu model: CpuTI");
   XBT_INFO("Task size: %f", task_comp_size);