Martin Ågren <martin.agren@xxxxxxxxx> writes: >> diff --git a/strbuf.h b/strbuf.h >> index 2075384e0b..1a77fe146a 100644 >> --- 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]); >> } >> >> /** > > When writing my patch, I used assert() and figured that with tsan, we're > in some sort of "debug"-mode anyway. If we decide to always do the > check, would it make sense to do "else if (strbuf_slopbuf[0]) BUG(..);" > instead of the assert? Or, if we do prefer the assert, would the > performance-worry be moot? I wasn't thinking about performance impact of having an assert(); the use of it in the above was merely copied from yours ;-)