diff options
author | Jeff King <peff@peff.net> | 2015-09-25 00:07:03 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-09-25 20:18:18 +0300 |
commit | 75faa45ae0230b321bf72027b2274315d7e14e34 (patch) | |
tree | 3b4aa1b362078ba4db498a087f3330ffe7affbd8 /builtin/ls-remote.c | |
parent | b7115a350b5c01ce0ae7a8735e4235d4b2367b5f (diff) |
replace trivial malloc + sprintf / strcpy calls with xstrfmt
It's a common pattern to do:
foo = xmalloc(strlen(one) + strlen(two) + 1 + 1);
sprintf(foo, "%s %s", one, two);
(or possibly some variant with strcpy()s or a more
complicated length computation). We can switch these to use
xstrfmt, which is shorter, involves less error-prone manual
computation, and removes many sprintf and strcpy calls which
make it harder to audit the code for real buffer overflows.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/ls-remote.c')
-rw-r--r-- | builtin/ls-remote.c | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c index 4554dbc8a9..5b6d679a63 100644 --- a/builtin/ls-remote.c +++ b/builtin/ls-remote.c @@ -93,12 +93,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) if (argv[i]) { int j; pattern = xcalloc(argc - i + 1, sizeof(const char *)); - for (j = i; j < argc; j++) { - int len = strlen(argv[j]); - char *p = xmalloc(len + 3); - sprintf(p, "*/%s", argv[j]); - pattern[j - i] = p; - } + for (j = i; j < argc; j++) + pattern[j - i] = xstrfmt("*/%s", argv[j]); } remote = remote_get(dest); if (!remote) { |