Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Replace sprintf by snprintf.
authordegomme <augustin.degomme@unibas.ch>
Tue, 31 May 2016 23:25:32 +0000 (01:25 +0200)
committerdegomme <augustin.degomme@unibas.ch>
Tue, 31 May 2016 23:25:32 +0000 (01:25 +0200)
20 files changed:
examples/msg/maestro-set/maestro-set.c
examples/msg/network-ns3/network-ns3.c
examples/smpi/NAS/dt.c
examples/smpi/NAS/ep.c
examples/smpi/smpi_msg_masterslave/masterslave_mailbox_smpi.c
src/bindings/lua/lua_debug.cpp
src/instr/jedule/jedule_output.cpp
src/simdag/dax_dtd.c
src/simdag/sd_dotloader.cpp
src/simgrid/sg_config.cpp
src/smpi/colls/smpi_automatic_selector.c
src/surf/maxmin.cpp
src/surf/ns3/ns3_simulator.h
src/surf/xml/simgrid_dtd.c
src/xbt/backtrace_linux.c
src/xbt/cunit.c
src/xbt/dict.c
src/xbt/mmalloc/mmorecore.c
src/xbt/xbt_str.c
teshsuite/msg/concurrent_rw/concurrent_rw.c

index 859f145..f22c97f 100644 (file)
@@ -38,7 +38,7 @@ static int sender(int argc, char *argv[])
 
   /* Latency */
   time = MSG_get_clock();
-  sprintf(sprintf_buffer_la, "latency task");
+  snprintf(sprintf_buffer_la,64, "latency task");
   task_la = MSG_task_create(sprintf_buffer_la, 0.0, task_comm_size_lat, NULL);
   task_la->data = xbt_new(double, 1);
   *(double *) task_la->data = time;
@@ -47,7 +47,7 @@ static int sender(int argc, char *argv[])
 
   /* Bandwidth */
   time = MSG_get_clock();
-  sprintf(sprintf_buffer_bw, "bandwidth task");
+  snprintf(sprintf_buffer_bw,64, "bandwidth task");
   task_bw = MSG_task_create(sprintf_buffer_bw, 0.0, task_comm_size_bw, NULL);
   task_bw->data = xbt_new(double, 1);
   *(double *) task_bw->data = time;
index 19b95c8..c422f5c 100644 (file)
@@ -36,7 +36,8 @@ static int master(int argc, char *argv[])
   /* worker name */
   char *workername = argv[2];
   int id = xbt_str_parse_int(argv[3], "Invalid ID as argument 3: %s");   //unique id to control statistics
-  char *id_alias = bprintf("flow_%d", id);
+  char *id_alias = xbt_malloc(20*sizeof(char));
+  snprintf(id_alias, 20, "flow_%d", id);
   workernames[id] = workername;
   TRACE_category(id_alias);
 
@@ -56,7 +57,7 @@ static int master(int argc, char *argv[])
   timer_start = 1 ;
 
   /* time measurement */
-  sprintf(id_alias, "%d", id);
+  snprintf(id_alias,20,"%d", id);
   start_time = MSG_get_clock();
   MSG_task_send(todo, id_alias);
   end_time = MSG_get_clock();
@@ -101,7 +102,7 @@ static int worker(int argc, char *argv[])
   XBT_DEBUG ("Worker started");
 
   int id = xbt_str_parse_int(argv[1], "Invalid id: %s");
-  sprintf(id_alias, "%d", id);
+  snprintf(id_alias,10, "%d", id);
 
   msg_error_t a = MSG_task_receive(&(task), id_alias);
 
index e38b99e..1c87e5a 100644 (file)
@@ -170,7 +170,7 @@ static DGraph *buildSH(const char cls){
   unsigned int i=0,j=0;
   char nm[BLOCK_SIZE];
 
-  snprintf(nm,BLOCK_SIZE -1,"DT_SH.%c",cls);
+  snprintf(nm,BLOCK_SIZE,"DT_SH.%c",cls);
   dg=newDGraph(nm);
 
   while(tmpS>1){
@@ -178,14 +178,14 @@ static DGraph *buildSH(const char cls){
   tmpS>>=1;
   }
   for(i=0;i<numSources;i++){
-  snprintf(nm,BLOCK_SIZE -1,"Source.%d",i);
+  snprintf(nm,BLOCK_SIZE,"Source.%d",i);
   nd=newNode(nm);
   AttachNode(dg,nd);
   }
   for(j=0;j<numOfLayers;j++){
     mask=0x00000001<<j;
     for(i=0;i<numSources;i++){
-      snprintf(nm,BLOCK_SIZE -1,"Comparator.%d",(i+j*firstLayerNode));
+      snprintf(nm,BLOCK_SIZE,"Comparator.%d",(i+j*firstLayerNode));
       nd=newNode(nm);
       AttachNode(dg,nd);
       ndoff=i&(~mask);
@@ -201,7 +201,7 @@ static DGraph *buildSH(const char cls){
   }
   mask=0x00000001<<numOfLayers;
   for(i=0;i<numSources;i++){
-    snprintf(nm,BLOCK_SIZE -1,"Sink.%d",i);
+    snprintf(nm,BLOCK_SIZE,"Sink.%d",i);
     nd=newNode(nm);
     AttachNode(dg,nd);
     ndoff=i&(~mask);
@@ -229,11 +229,11 @@ static DGraph *buildWH(const char cls){
   DGArc *ar=NULL;
   char nm[BLOCK_SIZE];
 
-  sprintf(nm,"DT_WH.%c",cls);
+  snprintf(nm,BLOCK_SIZE,"DT_WH.%c",cls);
   dg=newDGraph(nm);
 
   for(i=0;i<numSources;i++){
-    sprintf(nm,"Sink.%d",i);
+    snprintf(nm,BLOCK_SIZE,"Sink.%d",i);
     nd=newNode(nm);
     AttachNode(dg,nd);
   }
@@ -243,7 +243,7 @@ static DGraph *buildWH(const char cls){
     numLayerNodes=numLayerNodes/maxInDeg;
     if(numLayerNodes*maxInDeg<numPrevLayerNodes)numLayerNodes++;
     for(i=0;i<numLayerNodes;i++){
-      sprintf(nm,"Comparator.%d",totComparators);
+      snprintf(nm,BLOCK_SIZE,"Comparator.%d",totComparators);
       totComparators++;
       nd=newNode(nm);
       id=AttachNode(dg,nd);
@@ -289,11 +289,11 @@ static DGraph *buildBH(const char cls){
   int id=0, sid=0;
   char nm[BLOCK_SIZE];
 
-  sprintf(nm,"DT_BH.%c",cls);
+  snprintf(nm,BLOCK_SIZE,"DT_BH.%c",cls);
   dg=newDGraph(nm);
 
   for(i=0;i<numSources;i++){
-    sprintf(nm,"Source.%d",i);
+    snprintf(nm,BLOCK_SIZE,"Source.%d",i);
     nd=newNode(nm);
     AttachNode(dg,nd);
   }
@@ -301,7 +301,7 @@ static DGraph *buildBH(const char cls){
     numLayerNodes=numLayerNodes/maxInDeg;
     if(numLayerNodes*maxInDeg<numPrevLayerNodes)numLayerNodes++;
     for(i=0;i<numLayerNodes;i++){
-      sprintf(nm,"Comparator.%d",totComparators);
+      snprintf(nm,BLOCK_SIZE,"Comparator.%d",totComparators);
       totComparators++;
       nd=newNode(nm);
       id=AttachNode(dg,nd);
index 81707f2..60e6908 100644 (file)
@@ -62,7 +62,7 @@ int main(int argc, char **argv) {
      * string (for printing). Have to strip off the decimal point put in there by the floating point print statement
      * (internal file) */
     fprintf(stdout," NAS Parallel Benchmarks 3.2 -- EP Benchmark");
-    sprintf(size,"%lu",(unsigned long)pow(2,m+1));
+    snprintf(size,500,"%lu",(unsigned long)pow(2,m+1));
     //size = size.replace('.', ' ');
     fprintf(stdout," Number of random numbers generated: %s\n",size);
     fprintf(stdout," Number of active processes: %d\n",no_nodes);
index 9fe316b..7180271 100644 (file)
@@ -24,8 +24,8 @@ static int master(int argc, char *argv[])
     char sprintf_buffer[256];
     msg_task_t task = NULL;
 
-    sprintf(mailbox, "slave-%ld", i % slaves_count);
-    sprintf(sprintf_buffer, "Task_%d", i);
+    snprintf(mailbox,256, "slave-%ld", i % slaves_count);
+    snprintf(sprintf_buffer,256, "Task_%d", i);
     task = MSG_task_create(sprintf_buffer, task_comp_size, task_comm_size, NULL);
     if (number_of_tasks < 10000 || i % 10000 == 0)
       XBT_INFO("Sending \"%s\" (of %ld) to mailbox \"%s\"", task->name, number_of_tasks, mailbox);
@@ -37,7 +37,7 @@ static int master(int argc, char *argv[])
   for (i = 0; i < slaves_count; i++) {
     char mailbox[80];
 
-    sprintf(mailbox, "slave-%ld", i % slaves_count);
+    snprintf(mailbox,80, "slave-%ld", i % slaves_count);
     msg_task_t finalize = MSG_task_create("finalize", 0, 0, 0);
     MSG_task_send(finalize, mailbox);
   }
@@ -69,7 +69,8 @@ static int alltoall_mpi(int argc, char *argv[])
 {
   MPI_Init(&argc, &argv);
 
-  int rank, size;
+  int rank;
+  int size;
   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
   MPI_Comm_size(MPI_COMM_WORLD, &size);
   XBT_INFO("alltoall for rank %d", rank);
@@ -95,20 +96,17 @@ static int slave(int argc, char *argv[])
   read = sscanf(argv[1], "%d", &id);
   xbt_assert(read, "Invalid argument %s\n", argv[1]);
 
-  sprintf(mailbox, "slave-%d", id);
+  snprintf(mailbox,80, "slave-%d", id);
 
   while (1) {
     res = MSG_task_receive(&(task), mailbox);
     xbt_assert(res == MSG_OK, "MSG_task_get failed");
 
-//  XBT_INFO("Received \"%s\"", MSG_task_get_name(task));
-    if (!strcmp(MSG_task_get_name(task), "finalize")) {
+    if (strcmp(MSG_task_get_name(task), "finalize")==0) {
       MSG_task_destroy(task);
       break;
     }
-//    XBT_INFO("Processing \"%s\"", MSG_task_get_name(task));
     MSG_task_execute(task);
-//    XBT_INFO("\"%s\" done", MSG_task_get_name(task));
     MSG_task_destroy(task);
     task = NULL;
   }
index d0c0db6..171b847 100644 (file)
@@ -37,15 +37,15 @@ const char* sglua_tostring(lua_State* L, int index) {
   switch (lua_type(L, index)) {
 
     case LUA_TNIL:
-      sprintf(buff, "nil");
+      snprintf(buff, 4, "nil");
       break;
 
     case LUA_TNUMBER: 
-      sprintf(buff, "%.3f", lua_tonumber(L, index));
+      snprintf(buff, 64, "%.3f", lua_tonumber(L, index));
       break;
 
     case LUA_TBOOLEAN:
-      sprintf(buff, "%s", lua_toboolean(L, index) ? "true" : "false");
+      snprintf(buff, 64, "%s", lua_toboolean(L, index) ? "true" : "false");
       break;
 
     case LUA_TSTRING:
@@ -54,24 +54,24 @@ const char* sglua_tostring(lua_State* L, int index) {
 
     case LUA_TFUNCTION:
       if (lua_iscfunction(L, index)) {
-        sprintf(buff, "C-function");
+        snprintf(buff, 11, "C-function");
       }
       else {
-        sprintf(buff, "function");
+        snprintf(buff, 9, "function");
       }
       break;
 
     case LUA_TTABLE:
-      sprintf(buff, "table(%p)", lua_topointer(L, index));
+      snprintf(buff, 64, "table(%p)", lua_topointer(L, index));
       break;
 
     case LUA_TLIGHTUSERDATA:
     case LUA_TUSERDATA:
-      sprintf(buff, "userdata(%p)", lua_touserdata(L, index));
+      snprintf(buff, 64, "userdata(%p)", lua_touserdata(L, index));
       break;
 
     case LUA_TTHREAD:
-      sprintf(buff, "thread");
+      snprintf(buff, 7, "thread");
       break;
   }
   return buff;
@@ -164,7 +164,7 @@ void sglua_stack_dump(lua_State* L, const char* msg)
 
     p[0] = '\0';
     for (int i = 1; i <= top; i++) {  /* repeat for each level */
-      p += sprintf(p, "%s ", sglua_tostring(L, i));
+      p += snprintf(p, 2048-(p-buff), "%s ", sglua_tostring(L, i));
     }
 
     XBT_DEBUG("%s%s", msg, buff);
index a0c3461..f2d64da 100644 (file)
@@ -67,11 +67,11 @@ static void get_hierarchy_string(jed_simgrid_container_t container, char *outbuf
 
     xbt_dynar_foreach(hier_list, iter, number) {
         if( iter != length-1 ) {
-            sprintf(buf, "%d.", number);
+            snprintf(buf, 1024, "%d.", number);
         } else {
-            sprintf(buf, "%d", number);
+            snprintf(buf, 1024, "%d", number);
         }
-        strcat(outbuf, buf);
+        sntrcat(outbuf, buf, strlen(buf));
     }
 
     xbt_dynar_free(&hier_list);
index be760b5..4e78833 100644 (file)
@@ -3891,11 +3891,11 @@ static int fail(const char* fmt, ...)
     int chars_left, used;
     va_list ap; va_start(ap, fmt);
 #ifdef FLEXML_yylineno
-    used = sprintf(flexml_err_msg,
+    used = snprintf(flexml_err_msg,flexml_max_err_msg_size,
                   "Invalid XML (XML input line %d, state %d): ",
                   dax_lineno, YY_START);
 #else
-    used = sprintf(flexml_err_msg,
+    used = snprintf(flexml_err_msg,flexml_max_err_msg_size,
                   "Invalid XML (state %d): ",
                   YY_START);
 #endif
index 423df63..759b2b5 100644 (file)
@@ -167,8 +167,9 @@ xbt_dynar_t SD_dotload_generic(const char * filename, seq_par_t seq_or_par, bool
       dst = (SD_task_t)xbt_dict_get_or_null(jobs, dst_name);
 
       if (size > 0) {
-        char *name = (char*)xbt_malloc((strlen(src_name)+strlen(dst_name)+6)*sizeof(char));
-        sprintf(name, "%s->%s", src_name, dst_name);
+        int namesize=(strlen(src_name)+strlen(dst_name)+6);
+        char *name = (char*)xbt_malloc(namesize*sizeof(char*));
+        snprintf(name,namesize, "%s->%s", src_name, dst_name);
         XBT_DEBUG("See <transfer id=%s amount = %.0f>", name, size);
         if (!(task = (SD_task_t)xbt_dict_get_or_null(jobs, name))) {
           if (seq_or_par == sequential)
index d7b07e8..7578e05 100644 (file)
@@ -369,11 +369,11 @@ static void describe_model(char *result,
                            const char *description)
 {
   char *p = result +
-    sprintf(result, "%s. Possible values: %s", description,
+    snprintf(result,1024-strlen(result), "%s. Possible values: %s", description,
             model_description[0].name ? model_description[0].name : "n/a");
   for (int i = 1; model_description[i].name; i++)
-    p += sprintf(p, ", %s", model_description[i].name);
-  sprintf(p, ".\n       (use 'help' as a value to see the long description of each %s)", name);
+    p += snprintf(p,1024, ", %s", model_description[i].name);
+  snprintf(p,1024, ".\n       (use 'help' as a value to see the long description of each %s)", name);
 }
 
 /* create the config set, register what should be and parse the command line*/
index 0108d4c..29455c2 100644 (file)
@@ -15,7 +15,7 @@
              type=PJ_type_event_new(#cat, PJ_type_get_root());\
          }\
          char cont_name[25];\
-         sprintf(cont_name, "rank-%d", smpi_process_index());\
+         snprintf(cont_name,25, "rank-%d", smpi_process_index());\
          val_t value = PJ_value_get_or_new(mpi_coll_##cat##_description[i].name,"1.0 1.0 1.0", type);\
          new_pajeNewEvent (SIMIX_get_clock(), PJ_container_get(cont_name), type, value);\
       }
index 0ea8e65..abfb09b 100644 (file)
@@ -634,18 +634,18 @@ void lmm_print(lmm_system_t sys)
 
   /* Printing Objective */
   var_list = &(sys->variable_set);
-  sprintf(print_buf, "MAX-MIN ( ");
+  snprintf(print_buf,11, "MAX-MIN ( ");
   trace_buf = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
-  strcat(trace_buf, print_buf);
+  strncat(trace_buf, print_buf, strlen(print_buf));
   xbt_swag_foreach(_var, var_list) {
   var = (lmm_variable_t)_var;
-    sprintf(print_buf, "'%d'(%f) ", var->id_int, var->weight);
+    snprintf(print_buf,1024, "'%d'(%f) ", var->id_int, var->weight);
     trace_buf = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
-    strcat(trace_buf, print_buf);
+    strncat(trace_buf, print_buf, strlen(print_buf));
   }
-  sprintf(print_buf, ")");
+  snprintf(print_buf,2, ")");
   trace_buf = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
-  strcat(trace_buf, print_buf);
+  strncat(trace_buf, print_buf, strlen(print_buf));
   XBT_DEBUG("%20s", trace_buf);
   trace_buf[0] = '\000';
 
@@ -657,18 +657,18 @@ void lmm_print(lmm_system_t sys)
     sum = 0.0;
     //Show  the enabled variables
     elem_list = &(cnst->enabled_element_set);
-    sprintf(print_buf, "\t");
+    snprintf(print_buf,2, "\t");
     trace_buf = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
-    strcat(trace_buf, print_buf);
-    sprintf(print_buf, "%s(",(cnst->sharing_policy)?"":"max");
+    strncat(trace_buf, print_buf, strlen(print_buf));
+    snprintf(print_buf,1024, "%s(",(cnst->sharing_policy)?"":"max");
     trace_buf = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
-    strcat(trace_buf, print_buf);
+    strncat(trace_buf, print_buf, strlen(print_buf));
     xbt_swag_foreach(_elem, elem_list) {
       elem = (lmm_element_t)_elem;
-      sprintf(print_buf, "%f.'%d'(%f) %s ", elem->value,
+      snprintf(print_buf,1024, "%f.'%d'(%f) %s ", elem->value,
               elem->variable->id_int, elem->variable->value,(cnst->sharing_policy)?"+":",");
       trace_buf = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
-      strcat(trace_buf, print_buf);
+      strncat(trace_buf, print_buf, strlen(print_buf));
       if(cnst->sharing_policy)
         sum += elem->value * elem->variable->value;
       else 
@@ -678,24 +678,24 @@ void lmm_print(lmm_system_t sys)
     elem_list = &(cnst->disabled_element_set);
     xbt_swag_foreach(_elem, elem_list) {
       elem = (lmm_element_t)_elem;
-      sprintf(print_buf, "%f.'%d'(%f) %s ", elem->value,
+      snprintf(print_buf,1024, "%f.'%d'(%f) %s ", elem->value,
               elem->variable->id_int, elem->variable->value,(cnst->sharing_policy)?"+":",");
       trace_buf = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
-      strcat(trace_buf, print_buf);
+      strncat(trace_buf, print_buf, strlen(print_buf));
       if(cnst->sharing_policy)
         sum += elem->value * elem->variable->value;
       else 
         sum = MAX(sum,elem->value * elem->variable->value);
     }
 
-    sprintf(print_buf, "0) <= %f ('%d')", cnst->bound, cnst->id_int);
+    snprintf(print_buf,1024, "0) <= %f ('%d')", cnst->bound, cnst->id_int);
     trace_buf = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
-    strcat(trace_buf, print_buf);
+    strncat(trace_buf, print_buf, strlen(print_buf));
 
     if (!cnst->sharing_policy) {
-      sprintf(print_buf, " [MAX-Constraint]");
+      snprintf(print_buf,1024, " [MAX-Constraint]");
       trace_buf = (char*) xbt_realloc(trace_buf, strlen(trace_buf) + strlen(print_buf) + 1);
-      strcat(trace_buf, print_buf);
+      strncat(trace_buf, print_buf, strlen(print_buf));
     }
     XBT_DEBUG("%s", trace_buf);
     trace_buf[0] = '\000';
index 8cec673..1114a72 100644 (file)
@@ -44,7 +44,7 @@ static inline const char *transformSocketPtr (ns3::Ptr<ns3::Socket> localSocket)
   static char key[24];
   std::stringstream sstream;
   sstream << localSocket ;
-  sprintf(key,"%s",sstream.str().c_str());
+  snprintf(key,24,"%s",sstream.str().c_str());
 
   return key;
 }
index f316744..2af7590 100644 (file)
@@ -10305,11 +10305,11 @@ static int fail(const char* fmt, ...)
     int chars_left, used;
     va_list ap; va_start(ap, fmt);
 #ifdef FLEXML_yylineno
-    used = sprintf(flexml_err_msg,
+    used = snprintf(flexml_err_msg,flexml_max_err_msg_size,
                   "Invalid XML (XML input line %d, state %d): ",
                   surf_parse_lineno, YY_START);
 #else
-    used = sprintf(flexml_err_msg,
+    used = snprintf(flexml_err_msg,flexml_max_err_msg_size,
                   "Invalid XML (state %d): ",
                   YY_START);
 #endif
index e1de958..a1e3fcb 100644 (file)
@@ -170,9 +170,10 @@ void xbt_ex_setup_backtrace(xbt_ex_t * e) //FIXME: This code could be greatly im
   } else {
     binary_name = xbt_strdup(xbt_binary_name);
   }
-  cmd = curr = xbt_new(char, strlen(ADDR2LINE) + 25 + strlen(binary_name) + 32 * e->used);
+  int strsize=strlen(ADDR2LINE) + 25 + strlen(binary_name) + 32 * e->used;
+  cmd = curr = xbt_new(char, strsize);
 
-  curr += sprintf(curr, "%s -f -e %s ", ADDR2LINE, binary_name);
+  curr += snprintf(curr,strsize, "%s -f -e %s ", ADDR2LINE, binary_name);
   free(binary_name);
 
   addrs = xbt_new(char *, e->used);
@@ -190,7 +191,7 @@ void xbt_ex_setup_backtrace(xbt_ex_t * e) //FIXME: This code could be greatly im
     XBT_DEBUG("Set up a new address: %d, '%s'(%p)", i, addrs[i], addrs[i]);
 
     /* Add it to the command line args */
-    curr += sprintf(curr, "%s ", addrs[i]);
+    curr += snprintf(curr,strsize, "%s ", addrs[i]);
   }
   addr_len = strlen(addrs[0]);
 
@@ -289,7 +290,7 @@ void xbt_ex_setup_backtrace(xbt_ex_t * e) //FIXME: This code could be greatly im
       if (p[0] == '[') {
         /* library path not displayed in the map file either... */
         free(p);
-        sprintf(line_func, "??");
+        snprintf(line_func,3, "??");
       } else {
         p2 = strrchr(p, '(');
         if (p2)
index d4915f1..b669bfa 100644 (file)
@@ -266,7 +266,7 @@ static int xbt_test_suite_run(xbt_test_suite_t suite, int verbosity)
     suite_title[i++] = '\n';
     suite_title[80] = '\0';
 
-    sprintf(suite_title + 40 - (suite_len + 4) / 2, "[ %s ]", suite->title);
+    snprintf(suite_title + 40 - (suite_len + 4) / 2, 81-(40 - (suite_len + 4)/ 2), "[ %s ]", suite->title);
     suite_title[40 + (suite_len + 5) / 2] = '=';
     if (!suite->enabled)
       snprintf(suite_title + 70, 11, " DISABLED ");
index 6e2135d..8c98500 100644 (file)
@@ -982,7 +982,7 @@ XBT_TEST_UNIT("crash", test_dict_crash, "Crash test")
     /* if (!(j%1000)) { printf("."); fflush(stdout); } */
     key = xbt_malloc(10);
 
-    sprintf(key, "%d", j);
+    snprintf(key,10, "%d", j);
     xbt_dict_set(head, key, key, &free);
   }
   /*xbt_dict_dump(head,(void (*)(void*))&printf); */
@@ -997,7 +997,7 @@ XBT_TEST_UNIT("crash", test_dict_crash, "Crash test")
     void *data;
     /* if (i%10) printf("."); else printf("%d",i/10); fflush(stdout); */
     for (j = 0; j < NB_ELM; j++) {
-      sprintf(key, "%d", j);
+      snprintf(key,10, "%d", j);
       data = xbt_dict_get(head, key);
       xbt_test_assert(!strcmp(key, (char *) data), "with get, key=%s != data=%s", key, (char *) data);
       data = xbt_dict_get_ext(head, key, strlen(key));
@@ -1010,7 +1010,7 @@ XBT_TEST_UNIT("crash", test_dict_crash, "Crash test")
   key = xbt_malloc(10);
   for (j = 0; j < NB_ELM; j++) {
     /* if (!(j%10000)) printf("."); fflush(stdout); */
-    sprintf(key, "%d", j);
+    snprintf(key,10, "%d", j);
     xbt_dict_remove(head, key);
   }
   free(key);
index c80e74f..5227d08 100644 (file)
@@ -124,7 +124,7 @@ void *mmorecore(struct mdesc *mdp, ssize_t size)
       if (mapto == MAP_FAILED) {
         char buff[1024];
         fprintf(stderr,"Internal error: mmap returned MAP_FAILED! error: %s\n",strerror(errno));
-        sprintf(buff,"cat /proc/%d/maps",getpid());
+        snprintf(buff,1024,"cat /proc/%d/maps",getpid());
         int status = system(buff);
         if (status == -1 || !(WIFEXITED(status) && WEXITSTATUS(status) == 0))
           fprintf(stderr, "Something went wrong when trying to %s\n", buff);
index 6a54bb9..551aa99 100644 (file)
@@ -416,9 +416,9 @@ char *xbt_str_join(xbt_dynar_t dyn, const char *sep)
   p = res;
   xbt_dynar_foreach(dyn, cpt, cursor) {
     if ((int) cpt < dyn_len - 1)
-      p += sprintf(p, "%s%s", cursor, sep);
+      p += snprintf(p,len, "%s%s", cursor, sep);
     else
-      p += sprintf(p, "%s", cursor);
+      p += snprintf(p,len, "%s", cursor);
   }
   return res;
 }
@@ -449,9 +449,9 @@ char *xbt_str_join_array(const char *const *strs, const char *sep)
   q = res = xbt_malloc(len);
   for (i=0;strs[i];i++) {
     if (i!=0) { // not first loop
-      q += sprintf(q, "%s%s", sep, strs[i]);
+      q += snprintf(q,len, "%s%s", sep, strs[i]);
     } else {
-      q += sprintf(q,"%s",strs[i]);
+      q += snprintf(q,len, "%s",strs[i]);
     }
   }
   return res;
index 2024745..9231629 100644 (file)
@@ -15,7 +15,7 @@ static int host(int argc, char *argv[])
 {
   char name[2048];
   int id = MSG_process_self_PID();
-  sprintf(name,"%s%i", FILENAME1, id);
+  snprintf(name,2048,"%s%i", FILENAME1, id);
   msg_file_t file = MSG_file_open(name, NULL);
   XBT_INFO("process %d is writing!", id);
   MSG_file_write(file, 3000000);