From: Junio C Hamano Date: Mon, 29 Aug 2011 23:09:14 GMT Subject: Re: [PATCH] strbuf_grow(): maintain nul-termination even for new buffer Message-ID: <7vk49v4xyd.fsf@alter.siamese.dyndns.org> In-Reply-To: Thomas Rast 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.