From 9416c584571460f7bfde3b668db05b35643edc9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Wed, 25 Nov 2015 09:40:21 +0100 Subject: [PATCH] Check snprintf for -1 --- src/buffer.c | 4 ++++ src/dstr.c | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index 4a27e57..2ddb285 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -89,6 +89,10 @@ int uc_gbuf_printf(GBuf *buf, const char *fmt, ...) rc = vsnprintf(gbuf + buf->used, remaining, fmt, apc); va_end(apc); + if (rc == -1) { + break; + } + } while (rc >= remaining); if(rc > 0) { diff --git a/src/dstr.c b/src/dstr.c index a5ae33f..135d12b 100644 --- a/src/dstr.c +++ b/src/dstr.c @@ -279,12 +279,12 @@ int uc_dstr_vsprintf(struct DStr *str, const char *restrict fmt, va_list ap_) needed = vsnprintf(str->str + str->len, available, fmt, ap); va_end(ap); - if (needed <= 0) { + if (needed < 0) { return needed; } if (needed >= available) { - rc = uc_dstr_ensure(str, str->len + needed); + rc = uc_dstr_ensure(str, str->len + needed + 1); if (rc != 0) { return -1; }