summaryrefslogtreecommitdiffstats
path: root/openbsd-compat/bsd-asprintf.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2006-12-05 22:58:09 +1100
committerDamien Miller <djm@mindrot.org>2006-12-05 22:58:09 +1100
commitbe6db83462c0d4a7067ab303644440026c93d685 (patch)
tree6d5046270034586e766ce80c35aae7cab23745a1 /openbsd-compat/bsd-asprintf.c
parent143c2ef1ce072966d27d269d9acfed08796c390c (diff)
- (djm) [bsd-asprintf.c] Better test for bad vsnprintf lengths; ok dtucker@
Diffstat (limited to 'openbsd-compat/bsd-asprintf.c')
-rw-r--r--openbsd-compat/bsd-asprintf.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/openbsd-compat/bsd-asprintf.c b/openbsd-compat/bsd-asprintf.c
index 67480139..00fa0dfd 100644
--- a/openbsd-compat/bsd-asprintf.c
+++ b/openbsd-compat/bsd-asprintf.c
@@ -39,7 +39,8 @@
#define INIT_SZ 128
-int vasprintf(char **str, const char *fmt, va_list ap)
+int
+vasprintf(char **str, const char *fmt, va_list ap)
{
int ret = -1;
va_list ap2;
@@ -53,7 +54,7 @@ int vasprintf(char **str, const char *fmt, va_list ap)
ret = vsnprintf(string, INIT_SZ, fmt, ap2);
if (ret >= 0 && ret < INIT_SZ) { /* succeeded with initial alloc */
*str = string;
- } else if (ret == INT_MAX) { /* shouldn't happen */
+ } else if (ret == INT_MAX || ret < 0) { /* Bad length */
goto fail;
} else { /* bigger than initial, realloc allowing for nul */
len = (size_t)ret + 1;