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>

Jeff King committed Feb 22, 2016 at 17:45 UTC 21f9d0f6f2ef54185359d2d1c180770f85127199
1 file changed +3 -5
transport.c
+3 -5
@@ -1350,7 +1350,7 @@ int transport_disconnect(struct transport *transport)
1350 */
1351 char *transport_anonymize_url(const char *url)
1352 {
1353 - char *anon_url, *scheme_prefix, *anon_part;
1353 + char *scheme_prefix, *anon_part;
1354 size_t anon_len, prefix_len = 0;
1355
1356 anon_part = strchr(url, '@');
@@ -1384,10 +1384,8 @@ char *transport_anonymize_url(const char *url)
1384 goto literal_copy;
1385 prefix_len = scheme_prefix - url + 3;
1386 }
1387 - anon_url = xcalloc(1, 1 + prefix_len + anon_len);
1388 - memcpy(anon_url, url, prefix_len);
1389 - memcpy(anon_url + prefix_len, anon_part, anon_len);
1390 - return anon_url;
1387 + return xstrfmt("%.*s%.*s", (int)prefix_len, url,
1388 + (int)anon_len, anon_part);
1389 literal_copy:
1390 return xstrdup(url);
1391 }