From 68b9b0bc2a11d144870d14fcb8ac24e6c9c63354 Mon Sep 17 00:00:00 2001 From: William Hubbs Date: Sat, 10 Feb 2018 14:09:22 -0600 Subject: xasprintf: exit if return value of vsnprintf is invalid --- src/includes/helpers.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/includes') diff --git a/src/includes/helpers.h b/src/includes/helpers.h index 3657ee74..6e0ad19f 100644 --- a/src/includes/helpers.h +++ b/src/includes/helpers.h @@ -158,15 +158,12 @@ _unused static int xasprintf(char **strp, const char *fmt, ...) va_start(ap, fmt); len = vsnprintf(ret, len + 1, fmt, ap); va_end(ap); - if (len >= memlen) { - /* Give up! */ - free(ret); - return -1; - } } - if (len < 0) { + if (len < 0 || len >= memlen) { + /* Give up! */ + fprintf(stderr, "xasprintf: unable to format a buffer\n"); free(ret); - return -1; + exit(1); } *strp = ret; return len; -- cgit v1.2.3