]> git.ipfire.org Git - thirdparty/git.git/blobdiff - strbuf.h
strbuf_setlen: don't write to strbuf_slopbuf
[thirdparty/git.git] / strbuf.h
index 2075384e0b2df97a6d113acebcbcdcc853237166..1a77fe146a9c0a83bda4461b084148a5a89b63e2 100644 (file)
--- a/strbuf.h
+++ b/strbuf.h
@@ -147,7 +147,10 @@ static inline void strbuf_setlen(struct strbuf *sb, size_t len)
        if (len > (sb->alloc ? sb->alloc - 1 : 0))
                die("BUG: strbuf_setlen() beyond buffer");
        sb->len = len;
-       sb->buf[len] = '\0';
+       if (sb->buf != strbuf_slopbuf)
+               sb->buf[len] = '\0';
+       else
+               assert(!strbuf_slopbuf[0]);
 }
 
 /**