diff --git a/shared/strbuf.c b/shared/strbuf.c index 172558a..ef99eb7 100644 --- a/shared/strbuf.c +++ b/shared/strbuf.c @@ -36,12 +36,12 @@ static bool buf_realloc(struct strbuf *buf, size_t sz) static bool strbuf_reserve_extra(struct strbuf *buf, size_t n) { + if (n < buf->size - buf->used) + return true; + if (uaddsz_overflow(buf->used, n, &n) || n >= SIZE_MAX - BUF_STEP) return false; - if (n < buf->size) - return true; - if (++n % BUF_STEP) n = ((n / BUF_STEP) + 1) * BUF_STEP;