From 42409cb20c956bea7e678f4db5f17d27ee2bc422 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Sun, 7 Feb 2016 18:38:22 +0100 Subject: [PATCH] Kill some more atof --- examples/msg/bittorrent/tracker.c | 2 +- examples/msg/icomms/peer.c | 4 ++-- examples/msg/icomms/peer3.c | 2 +- examples/msg/semaphores/synchro.c | 4 ++-- src/surf/network_ib.cpp | 6 +++--- src/surf/plugins/energy.cpp | 12 +++++++----- src/surf/sg_platf.cpp | 2 +- src/surf/surf_routing.cpp | 2 +- teshsuite/msg/trace/test_trace_integration.c | 10 +++------- 9 files changed, 21 insertions(+), 23 deletions(-) diff --git a/examples/msg/bittorrent/tracker.c b/examples/msg/bittorrent/tracker.c index 15f6a94031..72ff0d1f67 100644 --- a/examples/msg/bittorrent/tracker.c +++ b/examples/msg/bittorrent/tracker.c @@ -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); diff --git a/examples/msg/icomms/peer.c b/examples/msg/icomms/peer.c index 77e6058aa2..1e322b4e0c 100644 --- a/examples/msg/icomms/peer.c +++ b/examples/msg/icomms/peer.c @@ -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); diff --git a/examples/msg/icomms/peer3.c b/examples/msg/icomms/peer3.c index 22072b4ae8..a0fe6c6196 100644 --- a/examples/msg/icomms/peer3.c +++ b/examples/msg/icomms/peer3.c @@ -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; diff --git a/examples/msg/semaphores/synchro.c b/examples/msg/semaphores/synchro.c index f64e7265c7..5919698b26 100644 --- a/examples/msg/semaphores/synchro.c +++ b/examples/msg/semaphores/synchro.c @@ -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); diff --git a/src/surf/network_ib.cpp b/src/surf/network_ib.cpp index 5ddb5e2ff4..8c64c0c860 100644 --- a/src/surf/network_ib.cpp +++ b/src/surf/network_ib.cpp @@ -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); } diff --git a/src/surf/plugins/energy.cpp b/src/surf/plugins/energy.cpp index 451dd832f4..c7ad3f8ecb 100644 --- a/src/surf/plugins/energy.cpp +++ b/src/surf/plugins/energy.cpp @@ -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(¤t_power_values); diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index be25920d42..62c611547b 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -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); diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index afb17ba2cc..96ec550920 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -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); diff --git a/teshsuite/msg/trace/test_trace_integration.c b/teshsuite/msg/trace/test_trace_integration.c index ff5292ce92..d0f52cf28c 100644 --- a/teshsuite/msg/trace/test_trace_integration.c +++ b/teshsuite/msg/trace/test_trace_integration.c @@ -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 ", 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); -- 2.20.1