Skip to content

Commit 21f9d0f

Browse files
peffgitster
authored andcommitted
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>
1 parent 7eb45b5 commit 21f9d0f

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

transport.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ int transport_disconnect(struct transport *transport)
13501350
*/
13511351
char *transport_anonymize_url(const char *url)
13521352
{
1353-
char *anon_url, *scheme_prefix, *anon_part;
1353+
char *scheme_prefix, *anon_part;
13541354
size_t anon_len, prefix_len = 0;
13551355

13561356
anon_part = strchr(url, '@');
@@ -1384,10 +1384,8 @@ char *transport_anonymize_url(const char *url)
13841384
goto literal_copy;
13851385
prefix_len = scheme_prefix - url + 3;
13861386
}
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);
13911389
literal_copy:
13921390
return xstrdup(url);
13931391
}

0 commit comments

Comments
 (0)