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; }