X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/fd769219531a772284d75320187a0ef9f8118afd..1b75ebf09b4d1b81533d140a9437efffeb9e6a0c:/src/instr/jedule/jedule_output.cpp diff --git a/src/instr/jedule/jedule_output.cpp b/src/instr/jedule/jedule_output.cpp index a0c34619e4..2b28d09404 100644 --- a/src/instr/jedule/jedule_output.cpp +++ b/src/instr/jedule/jedule_output.cpp @@ -15,6 +15,8 @@ #if HAVE_JEDULE +#define STR_BUF_SIZE 1024 + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(jed_out, jedule, "Logging specific to Jedule output"); xbt_dynar_t jedule_event_list; @@ -22,11 +24,11 @@ xbt_dynar_t jedule_event_list; static FILE *jed_file; static void get_hierarchy_list(xbt_dynar_t hier_list, jed_simgrid_container_t container) { - xbt_assert( container != NULL ); + xbt_assert( container != nullptr ); - if( container->parent != NULL ) { + if( container->parent != nullptr ) { - if( container->parent->container_children == NULL ) { + if( container->parent->container_children == nullptr ) { // we are in the last level get_hierarchy_list(hier_list, container->parent); } else { @@ -52,36 +54,36 @@ 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) { - char buf[1024]; +static void get_hierarchy_string(jed_simgrid_container_t container, char *outbuf, int bufsize) { + char buf[STR_BUF_SIZE]; xbt_dynar_t hier_list; unsigned int iter; int number; unsigned int length; outbuf[0] = '\0'; - hier_list = xbt_dynar_new(sizeof(int), NULL); + hier_list = xbt_dynar_new(sizeof(int), nullptr); get_hierarchy_list(hier_list, container); length = xbt_dynar_length(hier_list); xbt_dynar_foreach(hier_list, iter, number) { if( iter != length-1 ) { - sprintf(buf, "%d.", number); + snprintf(buf, STR_BUF_SIZE, "%d.", number); } else { - sprintf(buf, "%d", number); + snprintf(buf, STR_BUF_SIZE, "%d", number); } - strcat(outbuf, buf); + strncat(outbuf, buf, bufsize-strlen(outbuf)); } xbt_dynar_free(&hier_list); } static void print_key_value_dict(xbt_dict_t key_value_dict) { - xbt_dict_cursor_t cursor=NULL; + xbt_dict_cursor_t cursor=nullptr; char *key,*data; - if( key_value_dict != NULL ) { + if( key_value_dict != nullptr ) { xbt_dict_foreach(key_value_dict,cursor,key,data) { fprintf(jed_file, " \n",key,data); } @@ -92,12 +94,12 @@ static void print_resources(jed_simgrid_container_t resource_parent) { unsigned int res_nb; unsigned int i; char *res_name; - char resid[1024]; - xbt_assert( resource_parent->resource_list != NULL ); + char resid[STR_BUF_SIZE]; + xbt_assert( resource_parent->resource_list != nullptr ); res_nb = xbt_dynar_length(resource_parent->resource_list); - get_hierarchy_string(resource_parent, resid); + get_hierarchy_string(resource_parent, resid, STR_BUF_SIZE); fprintf(jed_file, " resource_list, i, res_name) { @@ -113,10 +115,10 @@ static void print_container(jed_simgrid_container_t container) { unsigned int i; jed_simgrid_container_t child_container; - xbt_assert( container != NULL ); + xbt_assert( container != nullptr ); fprintf(jed_file, " \n", container->name); - if( container->container_children != NULL ) { + if( container->container_children != nullptr ) { xbt_dynar_foreach(container->container_children, i, child_container) { print_container(child_container); } @@ -136,8 +138,8 @@ static void print_event(jed_event_t event) { unsigned int i; jed_res_subset_t subset; - xbt_assert( event != NULL ); - xbt_assert( event->resource_subsets != NULL ); + xbt_assert( event != nullptr ); + xbt_assert( event->resource_subsets != nullptr ); fprintf(jed_file, " \n"); @@ -151,9 +153,9 @@ static void print_event(jed_event_t event) { xbt_dynar_foreach(event->resource_subsets, i, subset) { int start = subset->start_idx; int end = subset->start_idx + subset->nres - 1; - char resid[1024]; + char resid[STR_BUF_SIZE]; - get_hierarchy_string(subset->parent, resid); + get_hierarchy_string(subset->parent, resid, STR_BUF_SIZE); fprintf(jed_file, "