Skip to content

Commit

Permalink
strbuf: make sure buffer is zero-terminated
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Erik Faye-Lund authored and Junio C Hamano committed Apr 11, 2011
1 parent e923eae commit 5e7a5d9
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion strbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5e7a5d9

Please sign in to comment.