git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[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
Next: Erik Faye-Lund
Message 1 of 7 in “strbuf: make sure buffer is zero-terminated”
  1. 1/2 strbuf: make sure buffer is zero-terminatedErik Faye-Lund, Apr 10, 2011
  2. 2/2 config: support values longer than 1023 bytesErik Faye-Lund, Apr 10, 2011
  3. Jeff KingApr 10, 2011
  4. Jeff KingApr 10, 2011
  5. Erik Faye-LundApr 10, 2011
  6. Jeff KingApr 10, 2011
  7. Junio C HamanoApr 11, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.