@matheusbsbs / matheus-bagliano / commits / 5e7a5d97f8
Fork 0

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 <kusmabite@gmail.com> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Erik Faye-Lund committed Apr 10, 2011 at 22:54 UTC 5e7a5d97f8a74181634a70e0e7b1464855c5af2d
1 file changed +3 -1
strbuf.c
+3 -1
@@ -30,8 +30,10 @@ void strbuf_init(struct strbuf *sb, size_t hint)
30 {
31 sb->alloc = sb->len = 0;
32 sb->buf = strbuf_slopbuf;
33 - if (hint)
33 + if (hint) {
34 strbuf_grow(sb, hint);
35 + sb->buf[0] = '\0';
36 + }
37 }
38
39 void strbuf_release(struct strbuf *sb)