提交 5e7a5d97 编写于 作者: E Erik Faye-Lund 提交者: Junio C Hamano

strbuf: make sure buffer is zero-terminated

strbuf_init does not zero-terminate the initial buffer when hint is
non-zero. Fix this so we can rely on the string to be zero-terminated
even if we haven't filled it with anything yet.
Signed-off-by: NErik Faye-Lund <kusmabite@gmail.com>
Acked-by: NJeff King <peff@peff.net>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 e923eaeb
......@@ -30,8 +30,10 @@ void strbuf_init(struct strbuf *sb, size_t hint)
{
sb->alloc = sb->len = 0;
sb->buf = strbuf_slopbuf;
if (hint)
if (hint) {
strbuf_grow(sb, hint);
sb->buf[0] = '\0';
}
}
void strbuf_release(struct strbuf *sb)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册