X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=strbuf.h;h=46a33f8c46985c4377071011d6ea48d6d3fe5331;hb=36612e4daf8b5b5eaf16315aa13c66925f878cd6;hp=e7e674bf1f9a2981e9f6dfbf6e51ba277ebcdc67;hpb=2f1d9e2b93e1b7fbfcfa59331db89dd6c76a3505;p=git.git diff --git a/strbuf.h b/strbuf.h index e7e674bf1..46a33f8c4 100644 --- a/strbuf.h +++ b/strbuf.h @@ -3,8 +3,6 @@ /* See Documentation/technical/api-strbuf.txt */ -#include - extern char strbuf_slopbuf[]; struct strbuf { size_t alloc; @@ -33,9 +31,8 @@ static inline size_t strbuf_avail(const struct strbuf *sb) { extern void strbuf_grow(struct strbuf *, size_t); static inline void strbuf_setlen(struct strbuf *sb, size_t len) { - if (!sb->alloc) - strbuf_grow(sb, 0); - assert(len < sb->alloc); + if (len > (sb->alloc ? sb->alloc - 1 : 0)) + die("BUG: strbuf_setlen() beyond buffer"); sb->len = len; sb->buf[len] = '\0'; }