Re: [PATCH 4/5] strbuf_reset: don't write to slopbuf with ThreadSanitizer
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 15, 2017, 19:19 UTC
- Message-ID
- <xmqq7ey4r64l.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <CAN0heSqwBNqrQPxOFZPCdFDA58P0JsKUqrw-KhVCcE1WKFTKbA@mail.gmail.com>
Martin Ågren <martin.agren@gmail.com> writes:
Show 22 quoted lines
>> 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 ;-)