[PATCH v2 1/2] strbuf: make sure buffer is zero-terminated
- From
Erik Faye-Lund <kusmabite@gmail.com>
- Date
- Apr 10, 2011, 20:54 UTC
- Message-ID
- <1302468858-7376-1-git-send-email-kusmabite@gmail.com>
strbuf_init does not zero-terminate the initial buffer when hint is non-zero. Fix this so strbuf_attach does not return garbage.
Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> --- strbuf.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/strbuf.c b/strbuf.c index 77444a9..09c43ae 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)
-- 1.7.4.msysgit.0.916.ga2194