From: Erik Faye-Lund Date: Sun, 10 Apr 2011 20:54:17 +0000 (+0200) Subject: strbuf: make sure buffer is zero-terminated X-Git-Tag: v1.7.6-rc0~143^2~1 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5e7a5d97f8a74181634a70e0e7b1464855c5af2d;p=git.git 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: Erik Faye-Lund Acked-by: Jeff King Signed-off-by: Junio C Hamano --- diff --git a/strbuf.c b/strbuf.c index bc3a0802e..73e040059 100644 --- a/strbuf.c +++ b/strbuf.c @@ -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)