From 6b28daccf7142bd4b00e9eee1cd63daa90ae4ad9 Mon Sep 17 00:00:00 2001 From: agiersch Date: Fri, 22 Oct 2010 09:29:15 +0000 Subject: [PATCH] Check return value of (v)asprintf. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8444 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- examples/amok/bandwidth/bandwidth.c | 7 +++---- examples/gras/p2p/chord/chord.c | 2 +- src/gras/DataDesc/ddt_create.c | 12 ++++++++---- src/simix/smx_global.c | 11 ++++++----- src/xbt/xbt_log_layout_simple.c | 3 ++- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/examples/amok/bandwidth/bandwidth.c b/examples/amok/bandwidth/bandwidth.c index e5d5de9b2d..28de73d037 100644 --- a/examples/amok/bandwidth/bandwidth.c +++ b/examples/amok/bandwidth/bandwidth.c @@ -92,11 +92,10 @@ int maestro(int argc, char *argv[]) gras_msg_handleall(5); /* friends, we're ready. Come and play */ if (xbt_dynar_length(group) < 2) { - char *msg; - asprintf(&msg, "Not enough peers arrived. Expected 2 got %ld", - xbt_dynar_length(group)); + CRITICAL1("Not enough peers arrived. Expected 2 got %ld", + xbt_dynar_length(group)); amok_pm_group_shutdown("bandwidth"); - xbt_die(msg); + xbt_abort(); } h1 = *(xbt_peer_t *) xbt_dynar_get_ptr(group, 0); h2 = *(xbt_peer_t *) xbt_dynar_get_ptr(group, 1); diff --git a/examples/gras/p2p/chord/chord.c b/examples/gras/p2p/chord/chord.c index debf98fbbe..f70b5ce928 100644 --- a/examples/gras/p2p/chord/chord.c +++ b/examples/gras/p2p/chord/chord.c @@ -312,7 +312,7 @@ int node(int argc, char **argv) if (argc == 3) { create = 1; } else { - asprintf(&other_host, "%s", argv[3]); + other_host = xbt_strdup(argv[3]); other_port = atoi(argv[4]); } diff --git a/src/gras/DataDesc/ddt_create.c b/src/gras/DataDesc/ddt_create.c index 77c19a5d83..4c8e3e27a9 100644 --- a/src/gras/DataDesc/ddt_create.c +++ b/src/gras/DataDesc/ddt_create.c @@ -694,7 +694,8 @@ gras_datadesc_dynar(gras_datadesc_type_t elm_t, void_f_pvoid_t free_func) char *buffname; gras_datadesc_type_t res; - asprintf(&buffname, "s_xbt_dynar_of_%s", elm_t->name); + if (asprintf(&buffname, "s_xbt_dynar_of_%s", elm_t->name) == -1) + xbt_die("asprintf failed"); res = gras_datadesc_struct(buffname); @@ -724,7 +725,8 @@ gras_datadesc_dynar(gras_datadesc_type_t elm_t, void_f_pvoid_t free_func) /* build a ref to it */ free(buffname); - asprintf(&buffname, "xbt_dynar_of_%s", elm_t->name); + if (asprintf(&buffname, "xbt_dynar_of_%s", elm_t->name) == -1) + xbt_die("asprintf failed"); res = gras_datadesc_ref(buffname, res); free(buffname); return res; @@ -758,7 +760,8 @@ gras_datadesc_matrix(gras_datadesc_type_t elm_t, char *buffname; gras_datadesc_type_t res; - asprintf(&buffname, "s_xbt_matrix_t(%s)", elm_t->name); + if (asprintf(&buffname, "s_xbt_matrix_t(%s)", elm_t->name) == -1) + xbt_die("asprintf failed"); res = gras_datadesc_struct(buffname); gras_datadesc_struct_append(res, "lines", @@ -783,7 +786,8 @@ gras_datadesc_matrix(gras_datadesc_type_t elm_t, /* build a ref to it */ free(buffname); - asprintf(&buffname, "xbt_matrix_t(%s)", elm_t->name); + if (asprintf(&buffname, "xbt_matrix_t(%s)", elm_t->name) == -1) + xbt_die("asprintf failed"); res = gras_datadesc_ref(buffname, res); free(buffname); return res; diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index a92036009a..9be6131b8e 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -104,11 +104,12 @@ void SIMIX_display_process_status(void) xbt_swag_foreach(process, simix_global->process_list) { char *who, *who2; - asprintf(&who, "%s on %s: %s", - process->name, - process->smx_host->name, - (process->blocked) ? "[BLOCKED] " - : ((process->suspended) ? "[SUSPENDED] " : "")); + if (asprintf(&who, "%s on %s: %s", + process->name, + process->smx_host->name, + (process->blocked) ? "[BLOCKED] " + : ((process->suspended) ? "[SUSPENDED] " : "")) == -1) + xbt_die("asprintf failed"); if (process->mutex) { who2 = diff --git a/src/xbt/xbt_log_layout_simple.c b/src/xbt/xbt_log_layout_simple.c index 030a17b55f..ddb77e929b 100644 --- a/src/xbt/xbt_log_layout_simple.c +++ b/src/xbt/xbt_log_layout_simple.c @@ -46,7 +46,8 @@ static void xbt_log_layout_simple_dynamic(xbt_log_layout_t l, xbt_strbuff_append(buff, loc_buff); - vasprintf(&p, fmt, ev->ap_copy); + if (vasprintf(&p, fmt, ev->ap_copy) == -1) + xbt_die("vasprintf failed"); xbt_strbuff_append(buff, p); free(p); -- 2.20.1