Browse Source

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>
maint
Erik Faye-Lund 14 years ago committed by Junio C Hamano
parent
commit
5e7a5d97f8
  1. 4
      strbuf.c

4
strbuf.c

@ -30,8 +30,10 @@ void strbuf_init(struct strbuf *sb, size_t hint) @@ -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)

Loading…
Cancel
Save