Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill all atol() from our codebase
authorMartin Quinson <martin.quinson@loria.fr>
Sun, 7 Feb 2016 17:14:19 +0000 (18:14 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sun, 7 Feb 2016 17:14:19 +0000 (18:14 +0100)
examples/msg/icomms/peer.c
examples/msg/icomms/peer2.c
examples/msg/icomms/peer3.c
examples/msg/masterslave/masterslave_arg.c
examples/msg/masterslave/masterslave_mailbox.c
examples/msg/tracing/categories.c
examples/msg/tracing/ms.c
examples/smpi/smpi_msg_masterslave/masterslave_mailbox_smpi.c
src/smpi/smpi_base.cpp
src/surf/network_smpi.cpp
src/xbt/xbt_log_appender_file.c

index a94c91e..77e6058 100644 (file)
@@ -34,12 +34,12 @@ msg_error_t test_all(const char *platform_file,
 /** Sender function  */
 int sender(int argc, char *argv[])
 {
-  long number_of_tasks = atol(argv[1]);
-  double task_comp_size = atof(argv[2]);
-  double task_comm_size = atof(argv[3]);
-  long receivers_count = atol(argv[4]);
-  double sleep_start_time = atof(argv[5]);
-  double sleep_test_time = atof(argv[6]);
+  long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
+  double task_comp_size = xbt_str_parse_double(argv[2], "Invalid compute size: %s");
+  double task_comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s");
+  long receivers_count = xbt_str_parse_int(argv[4], "Invalid amount of receivers: %s");
+  double sleep_start_time = xbt_str_parse_double(argv[5], "Invalid sleep start time: %s");
+  double sleep_test_time = xbt_str_parse_double(argv[6], "Invalid test time: %s");
 
   XBT_INFO("sleep_start_time : %f , sleep_test_time : %f", sleep_start_time,
         sleep_test_time);
index b5b4b5b..a2cf462 100644 (file)
@@ -28,10 +28,10 @@ msg_error_t test_all(const char *platform_file,
 /** Sender function  */
 int sender(int argc, char *argv[])
 {
-  long number_of_tasks = atol(argv[1]);
-  double task_comp_size = atof(argv[2]);
-  double task_comm_size = atof(argv[3]);
-  long receivers_count = atol(argv[4]);
+  long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
+  double task_comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s");
+  double task_comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s");
+  long receivers_count = xbt_str_parse_int(argv[4], "Invalid amount of receivers: %s");
 
   msg_comm_t *comm = xbt_new(msg_comm_t, number_of_tasks + receivers_count);
   int i;
index 155b702..22072b4 100644 (file)
@@ -28,11 +28,11 @@ msg_error_t test_all(const char *platform_file,
 /** Sender function  */
 int sender(int argc, char *argv[])
 {
-  long number_of_tasks = atol(argv[1]);
-  double task_comp_size = atof(argv[2]);
-  double task_comm_size = atof(argv[3]);
-  long receivers_count = atol(argv[4]);
-  int diff_com = atol(argv[5]);
+  long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
+  double task_comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s");
+  double task_comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s");
+  long receivers_count = xbt_str_parse_int(argv[4], "Invalid amount of receivers: %s");
+  int diff_com = xbt_str_parse_int(argv[5], "Invalid value for diff_comm: %s");
   double coef = 0;
   xbt_dynar_t d = xbt_dynar_new(sizeof(msg_comm_t), NULL);
   int i;
index ecaafac..611b26d 100644 (file)
@@ -98,8 +98,8 @@ int main(int argc, char *argv[])
 
   MSG_create_environment(argv[1]);
 
-  number_of_jobs = atol(argv[2]);
-  number_of_slaves = atol(argv[3]);
+  number_of_jobs = xbt_str_parse_int(argv[2], "Invalid amount of jobs: %s");
+  number_of_slaves = xbt_str_parse_int(argv[3], "Invalid amount of slaves: %s");
   xbt_dynar_t host_dynar = MSG_hosts_as_dynar();
   long number_max = xbt_dynar_length(host_dynar);
   XBT_INFO("Got %ld slaves, %ld tasks to process, and %ld hosts", number_of_slaves, number_of_jobs,number_max);
index 7737722..8c4c100 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <stdio.h>
 #include "simgrid/msg.h"        /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
-#include "xbt/sysdep.h"         /* calloc, printf */
+#include "xbt/sysdep.h"
 
 /* Create a log channel to have nice outputs. */
 #include "xbt/log.h"
@@ -17,18 +17,17 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
 int master(int argc, char *argv[]);
 int slave(int argc, char *argv[]);
 
-/** Emitter function  */
+/** Sender function  */
 int master(int argc, char *argv[])
 {
-  long number_of_tasks = atol(argv[1]);
-  double task_comp_size = atof(argv[2]);
-  double task_comm_size = atof(argv[3]);
-  long slaves_count = atol(argv[4]);
+  long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
+  double task_comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s");
+  double task_comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s");
+  long slaves_count = xbt_str_parse_int(argv[4], "Invalid amount of slaves: %s");
 
   int i;
 
-  XBT_INFO("Got %ld slaves and %ld tasks to process", slaves_count,
-        number_of_tasks);
+  XBT_INFO("Got %ld slaves and %ld tasks to process", slaves_count, number_of_tasks);
 
   for (i = 0; i < number_of_tasks; i++) {
     char mailbox[256];
index f47b7b1..f5e3fc9 100644 (file)
@@ -32,11 +32,11 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
 int master(int argc, char *argv[]);
 int slave(int argc, char *argv[]);
 
-/** Emitter function  */
+/** sender function  */
 int master(int argc, char *argv[])
 {
-  long number_of_tasks = atol(argv[1]);
-  long slaves_count = atol(argv[4]);
+  long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
+  long slaves_count = xbt_str_parse_int(argv[4], "Invalid amount of slaves: %s");
 
   int i;
   for (i = 0; i < number_of_tasks; i++) {
index 18d7b11..697a814 100644 (file)
@@ -32,13 +32,13 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
 int master(int argc, char *argv[]);
 int slave(int argc, char *argv[]);
 
-/** Emitter function  */
+/** sender function  */
 int master(int argc, char *argv[])
 {
-  long number_of_tasks = atol(argv[1]);
-  double task_comp_size = atof(argv[2]);
-  double task_comm_size = atof(argv[3]);
-  long slaves_count = atol(argv[4]);
+  long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
+  double task_comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s");
+  double task_comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s");
+  long slaves_count = xbt_str_parse_int(argv[4], "Invalid amount of slaves: %s");
 
   //setting the variable "is_master" (previously declared) to value 1
   TRACE_host_variable_set(MSG_host_get_name(MSG_host_self()), "is_master", 1);
index f0b2daa..119c30f 100644 (file)
@@ -19,18 +19,17 @@ int slave(int argc, char *argv[]);
 int master_mpi(int argc, char *argv[]);
 int alltoall_mpi(int argc, char *argv[]);
 
-/** Emitter function  */
+/** sender function  */
 int master(int argc, char *argv[])
 {
-  long number_of_tasks = atol(argv[1]);
-  double task_comp_size = atof(argv[2]);
-  double task_comm_size = atof(argv[3]);
-  long slaves_count = atol(argv[4]);
+  long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
+  double task_comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s");
+  double task_comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s");
+  long slaves_count = xbt_str_parse_int(argv[4], "Invalid amount of slaves: %s");
 
   int i;
 
-  XBT_INFO("Got %ld slaves and %ld tasks to process", slaves_count,
-        number_of_tasks);
+  XBT_INFO("Got %ld slaves and %ld tasks to process", slaves_count, number_of_tasks);
 
   for (i = 0; i < number_of_tasks; i++) {
     char mailbox[256];
index 8d66a02..4cbf4ed 100644 (file)
@@ -103,9 +103,11 @@ static xbt_dynar_t parse_factor(const char *smpi_coef_string)
       xbt_die("Malformed radical for smpi factor: '%s'", smpi_coef_string);
     for(i =0; i<xbt_dynar_length(radical_elements2);i++ ){
         if (i==0){
-           fact.factor = atol(xbt_dynar_get_as(radical_elements2, i, char *));
+           fact.factor = xbt_str_parse_int(xbt_dynar_get_as(radical_elements2, i, char *),
+               bprintf("Invalid factor in chunk #%d: %%s", iter+1));
         }else{
-           fact.values[fact.nb_values] = atof(xbt_dynar_get_as(radical_elements2, i, char *));
+           fact.values[fact.nb_values] = xbt_str_parse_double(xbt_dynar_get_as(radical_elements2, i, char *),
+               bprintf("Invalid factor value %d in chunk #%d: %%s", i, iter+1));
            fact.nb_values++;
         }
     }
index 5bb1548..856e560 100644 (file)
@@ -47,8 +47,12 @@ static xbt_dynar_t parse_factor(const char *smpi_coef_string)
     radical_elements2 = xbt_str_split(value, ":");
     if (xbt_dynar_length(radical_elements2) != 2)
       surf_parse_error("Malformed radical for smpi factor!");
-    fact.factor = atol(xbt_dynar_get_as(radical_elements2, 0, char *));
-    fact.value = atof(xbt_dynar_get_as(radical_elements2, 1, char *));
+
+    fact.factor = xbt_str_parse_int(xbt_dynar_get_as(radical_elements2, 0, char *),
+        bprintf("Invalid factor in chunk #%d: %%s", iter+1));
+    fact.value = xbt_str_parse_double(xbt_dynar_get_as(radical_elements2, 1, char *),
+        bprintf("Invalid factor value in chunk #%d: %%s", iter+1));
+
     xbt_dynar_push_as(smpi_factor, s_smpi_factor_t, fact);
     XBT_DEBUG("smpi_factor:\t%ld : %f", fact.factor, fact.value);
     xbt_dynar_free(&radical_elements2);
index 7033d6e..82f8141 100644 (file)
@@ -138,7 +138,10 @@ xbt_log_appender_t xbt_log_appender2_file_new(char *arg,int roll) {
   xbt_assert(sep>0);
   data->filename=xbt_strdup(sep+1);
   *sep='\0';
-  data->limit=atol(buf);
+  char *endptr;
+  data->limit=strtol(buf,&endptr,10);
+  xbt_assert(endptr[0]=='\0', "Invalid buffer size: %s", buf);
+  xbt_free(buf);
   if(roll)
     data->count=-1;
   else