From 2d23cdc9f4cdbe97374ee6892c17feb255f88ee9 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 17 Sep 2013 00:26:44 -0400 Subject: [PATCH] check asprintf return value The current asprintf usage triggers many warnings like: sslh-main.c: In function 'print_usage': sslh-main.c:86:17: warning: ignoring return value of 'asprintf', declared with attribute warn_unused_result [-Wunused-result] Signed-off-by: Mike Frysinger --- common.c | 4 +++- probe.c | 3 ++- sslh-main.c | 7 +++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/common.c b/common.c index 3d570d0..2f008d5 100644 --- a/common.c +++ b/common.c @@ -487,9 +487,11 @@ void setup_signals(void) * banner is made up of basename(bin_name)+"[pid]" */ void setup_syslog(const char* bin_name) { char *name1, *name2; + int res; name1 = strdup(bin_name); - asprintf(&name2, "%s[%d]", basename(name1), getpid()); + res = asprintf(&name2, "%s[%d]", basename(name1), getpid()); + CHECK_RES_DIE(res, "asprintf"); openlog(name2, LOG_CONS, LOG_AUTH); free(name1); /* Don't free name2, as openlog(3) uses it (at least in glibc) */ diff --git a/probe.c b/probe.c index d693797..fa34f96 100644 --- a/probe.c +++ b/probe.c @@ -63,7 +63,8 @@ int get_num_builtins(void) { /* Sets the protocol name to connect to in case of timeout */ void set_ontimeout(const char* name) { - asprintf(&on_timeout, "%s", name); + int res = asprintf(&on_timeout, "%s", name); + CHECK_RES_DIE(res, "asprintf"); } /* Returns the protocol to connect to in case of timeout; diff --git a/sslh-main.c b/sslh-main.c index a3b8352..a522b1a 100644 --- a/sslh-main.c +++ b/sslh-main.c @@ -79,11 +79,14 @@ static void print_usage(void) { struct proto *p; int i; + int res; char *prots = ""; p = get_builtins(); - for (i = 0; i < get_num_builtins(); i++) - asprintf(&prots, "%s\t[--%s ]\n", prots, p[i].description); + for (i = 0; i < get_num_builtins(); i++) { + res = asprintf(&prots, "%s\t[--%s ]\n", prots, p[i].description); + CHECK_RES_DIE(res, "asprintf"); + } fprintf(stderr, USAGE_STRING, prots); }