X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=strbuf.h;h=9e6d9fa53fc04156452bf850af1a9b2d3ba830f2;hb=df6b0cad5f2d2f1984d1538de03e1e8ac87a78a2;hp=07060ce893d8303b7eb4d78db0f7a5575527f88f;hpb=a8793d2178b8305be55b1c88ac13fbb7dc52a076;p=git.git diff --git a/strbuf.h b/strbuf.h index 07060ce89..9e6d9fa53 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'; }