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

[PATCH] strbuf: use valid pointer in strbuf_remove()

From
René Scharfe <l.s.r@web.de>
Date
Sep 13, 2016, 16:40 UTC
Message-ID
<408af1a3-6867-2ff5-c97f-3eb884412ad8@web.de>

The fourth argument of strbuf_splice() is passed to memcpy(3), which is not supposed to handle NULL pointers. Let's be extra careful and use a valid empty string instead. It even shortens the source code. :)

Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 strbuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/strbuf.c b/strbuf.c
index f3bd571..b839be4 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -187,7 +187,7 @@ void strbuf_insert(struct strbuf *sb, size_t pos, const void *data, size_t len)
 
 void strbuf_remove(struct strbuf *sb, size_t pos, size_t len)
 {
-	strbuf_splice(sb, pos, len, NULL, 0);
+	strbuf_splice(sb, pos, len, "", 0);
 }
 
 void strbuf_add(struct strbuf *sb, const void *data, size_t len)
-- 
2.10.0
Next: Jeff King
Message 1 of 2 in “strbuf: use valid pointer in strbuf_remove()”
  1. strbuf: use valid pointer in strbuf_remove()René Scharfe, Sep 13, 2016
  2. Jeff KingSep 13, 2016

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.