summaryrefslogtreecommitdiff
path: root/transport.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-02-22 17:45:05 -0500
committerJunio C Hamano <gitster@pobox.com>2016-02-22 14:51:09 -0800
commit21f9d0f6f2ef54185359d2d1c180770f85127199 (patch)
treeb9054a5dca7d951babc8a707b73c8ce2bb0fe293 /transport.c
parent7eb45b5f78e257a682ec825839b4b33e025a9615 (diff)
downloadgit-21f9d0f6f2ef54185359d2d1c180770f85127199.tar.gz
transport_anonymize_url: use xstrfmt
This function uses xcalloc and two memcpy calls to concatenate two strings. We can do this as an xstrfmt one-liner, and then it is more clear that we are allocating the correct amount of memory. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'transport.c')
-rw-r--r--transport.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/transport.c b/transport.c
index 163abedcb0..988047b12e 100644
--- a/transport.c
+++ b/transport.c
@@ -1350,7 +1350,7 @@ int transport_disconnect(struct transport *transport)
*/
char *transport_anonymize_url(const char *url)
{
- char *anon_url, *scheme_prefix, *anon_part;
+ char *scheme_prefix, *anon_part;
size_t anon_len, prefix_len = 0;
anon_part = strchr(url, '@');
@@ -1384,10 +1384,8 @@ char *transport_anonymize_url(const char *url)
goto literal_copy;
prefix_len = scheme_prefix - url + 3;
}
- anon_url = xcalloc(1, 1 + prefix_len + anon_len);
- memcpy(anon_url, url, prefix_len);
- memcpy(anon_url + prefix_len, anon_part, anon_len);
- return anon_url;
+ return xstrfmt("%.*s%.*s", (int)prefix_len, url,
+ (int)anon_len, anon_part);
literal_copy:
return xstrdup(url);
}