threads / patch / 38242

patchtransport: simplify duplicating a substring in transport_get() using xmemdupz()

Subject: [PATCH] transport: simplify duplicating a substring in transport_get() using xmemdupz()

## tl;dr

2 messages between Dec 24, 2014 and Dec 24, 2014. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

René Scharfe· Dec 24, 2014, 00:18 UTC · lore
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
 transport.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
Show changes to transport.c +1 −3
diff --git a/transport.c b/transport.c
index 70d38e4..08bcd3a 100644
--- a/transport.c
+++ b/transport.c
@@ -971,9 +971,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
 	} else {
 		/* Unknown protocol in URL. Pass to external handler. */
 		int len = external_specification_len(url);
-		char *handler = xmalloc(len + 1);
-		handler[len] = 0;
-		strncpy(handler, url, len);
+		char *handler = xmemdupz(url, len);
 		transport_helper_init(ret, handler);
 	}
 
-- 
2.2.1
Jonathan Nieder· Dec 24, 2014, 02:08 UTC · re: René Scharfe · lore

Re: [PATCH] transport: simplify duplicating a substring in transport_get() using xmemdupz()

René Scharfe wrote:
> Signed-off-by: Rene Scharfe <l.s.r@web.de>
> ---
>  transport.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)

Since external_specification_len(url) is defined to always be less than strlen(url) when is_url(url), this should be safe.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>

← back to recent threads