Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix the fix: compute the real buffer size
[simgrid.git] / src / instr / jedule / jedule_output.cpp
index a0c3461..3987403 100644 (file)
@@ -52,7 +52,7 @@ static void get_hierarchy_list(xbt_dynar_t hier_list, jed_simgrid_container_t co
   }
 }
 
-static void get_hierarchy_string(jed_simgrid_container_t container, char *outbuf) {
+static void get_hierarchy_string(jed_simgrid_container_t container, char *outbuf, int bufsize) {
     char buf[1024];
     xbt_dynar_t hier_list;
     unsigned int iter;
@@ -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);
+        strncat(outbuf, buf, bufsize-strlen(outbuf)-1);
     }
 
     xbt_dynar_free(&hier_list);
@@ -92,12 +92,12 @@ static void print_resources(jed_simgrid_container_t resource_parent) {
   unsigned int res_nb;
   unsigned int i;
   char *res_name;
-    char resid[1024];
+  char resid[1024];
   xbt_assert( resource_parent->resource_list != NULL );
 
   res_nb = xbt_dynar_length(resource_parent->resource_list);
 
-  get_hierarchy_string(resource_parent, resid);
+  get_hierarchy_string(resource_parent, resid, 1024);
 
   fprintf(jed_file, "      <rset id=\"%s\" nb=\"%d\" names=\"", resid, res_nb);
   xbt_dynar_foreach(resource_parent->resource_list, i, res_name) {
@@ -153,7 +153,7 @@ static void print_event(jed_event_t event) {
     int end   = subset->start_idx + subset->nres - 1;
     char resid[1024];
 
-    get_hierarchy_string(subset->parent, resid);
+    get_hierarchy_string(subset->parent, resid, 1024);
     fprintf(jed_file, "        <select resources=\"");
     fprintf(jed_file, "%s", resid);
     fprintf(jed_file, ".[%d-%d]", start, end);