Skip to content

Commit 5e7a5d9

Browse files
kusmagitster
authored andcommitted
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 <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e923eae commit 5e7a5d9

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

strbuf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ void strbuf_init(struct strbuf *sb, size_t hint)
3030
{
3131
sb->alloc = sb->len = 0;
3232
sb->buf = strbuf_slopbuf;
33-
if (hint)
33+
if (hint) {
3434
strbuf_grow(sb, hint);
35+
sb->buf[0] = '\0';
36+
}
3537
}
3638

3739
void strbuf_release(struct strbuf *sb)

0 commit comments

Comments
 (0)