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

2 messages from 2014-12-24 to 2014-12-24. Participants: René Scharfe, Jonathan Nieder.
Thread: https://gitlist.dev/t/38242

## René Scharfe, 2014-12-24 00:18

Subject: [PATCH] transport: simplify duplicating a substring in transport_get() using xmemdupz()
Message-ID: <549A0657.6010509@web.de>
URL: https://gitlist.dev/e/549A0657.6010509%40web.de

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

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, 2014-12-24 02:08

Subject: Re: [PATCH] transport: simplify duplicating a substring in transport_get() using xmemdupz()
Message-ID: <20141224020847.GC29365@google.com>
URL: https://gitlist.dev/e/20141224020847.GC29365%40google.com
In-Reply-To: <549A0657.6010509@web.de>

```
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>

```
