aboutsummaryrefslogtreecommitdiff
path: root/src/includes
diff options
context:
space:
mode:
authorWilliam Hubbs <w.d.hubbs@gmail.com>2018-02-10 14:09:22 -0600
committerWilliam Hubbs <w.d.hubbs@gmail.com>2018-02-10 14:49:40 -0600
commit68b9b0bc2a11d144870d14fcb8ac24e6c9c63354 (patch)
tree596f29c2d201b53eaf766eba34559d7444599208 /src/includes
parent4616f8f809ee8566904ca37f2b8bf0409a487475 (diff)
xasprintf: exit if return value of vsnprintf is invalid
Diffstat (limited to 'src/includes')
-rw-r--r--src/includes/helpers.h11
1 files changed, 4 insertions, 7 deletions
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;