git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] strbuf: use valid pointer in strbuf_remove()
@ 2016-09-13 16:40 René Scharfe
  2016-09-13 18:14 ` Jeff King
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2016-09-13 16:40 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] strbuf: use valid pointer in strbuf_remove()
  2016-09-13 16:40 [PATCH] strbuf: use valid pointer in strbuf_remove() René Scharfe
@ 2016-09-13 18:14 ` Jeff King
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff King @ 2016-09-13 18:14 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git List, Junio C Hamano

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-09-13 18:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-13 16:40 [PATCH] strbuf: use valid pointer in strbuf_remove() René Scharfe
2016-09-13 18:14 ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).