Check snprintf for -1
This commit is contained in:
@@ -89,6 +89,10 @@ int uc_gbuf_printf(GBuf *buf, const char *fmt, ...)
|
|||||||
rc = vsnprintf(gbuf + buf->used, remaining, fmt, apc);
|
rc = vsnprintf(gbuf + buf->used, remaining, fmt, apc);
|
||||||
va_end(apc);
|
va_end(apc);
|
||||||
|
|
||||||
|
if (rc == -1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
} while (rc >= remaining);
|
} while (rc >= remaining);
|
||||||
|
|
||||||
if(rc > 0) {
|
if(rc > 0) {
|
||||||
|
|||||||
+2
-2
@@ -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);
|
needed = vsnprintf(str->str + str->len, available, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if (needed <= 0) {
|
if (needed < 0) {
|
||||||
return needed;
|
return needed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needed >= available) {
|
if (needed >= available) {
|
||||||
rc = uc_dstr_ensure(str, str->len + needed);
|
rc = uc_dstr_ensure(str, str->len + needed + 1);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user