threads / patch / 44073

patchstrbuf: use valid pointer in strbuf_remove()

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

## tl;dr

2 messages between Sep 13, 2016 and Sep 13, 2016. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

René Scharfe· Sep 13, 2016, 16:40 UTC · lore

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(-)
Show changes to strbuf.c +1 −1
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
Jeff King· Sep 13, 2016, 18:14 UTC · re: René Scharfe · lore

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

On Tue, Sep 13, 2016 at 06:40:22PM +0200, René Scharfe wrote:
> 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. :)
Heh. Looks obviously correct and like a good thing to do.
-Peff

← back to recent threads