Re: [PATCH] strbuf_grow(): maintain nul-termination even for new buffer
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 29, 2011, 23:09 UTC
- Message-ID
- <7vk49v4xyd.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <c8d8686c1813885a36d8f4cada218686989df236.1314651926.git.trast@student.ethz.ch>
Thomas Rast <trast@student.ethz.ch> writes:
> So make sure that strbuf_grow() puts in a nul even if it has nowhere > to copy it from. This makes strbuf_grow(sb, 0) a semantic no-op as > far as readers of the buffer are concerned.
Makes sense, thanks.
> Also remove the nul-termination added by strbuf_init, which is made > redudant.
Ok.
This is a tangent but if we do not have hint, we point at strbuf_slopbuf[] which is:
/*
* Used as the default ->buf value, so that people can always assume
* buf is non NULL and ->buf is NUL terminated even for a freshly
* initialized strbuf.
*/
char strbuf_slopbuf[1];While nobody should be writing into it, we do not really enforce the constness of this buffer.
I wonder if it would be worth making this into "const char []" and have the complier/linker move it to read-only section to catch potential bugs.