diff options
author | Jeff King <peff@peff.net> | 2014-06-19 17:26:56 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-06-19 15:20:54 -0700 |
commit | b2724c87872aaec55dd7e5529aa029c3108b43a5 (patch) | |
tree | 905e0c855f087699b8a5fd8054271a8e7c5d9dad /builtin/fetch.c | |
parent | use xstrfmt to replace xmalloc + sprintf (diff) | |
download | tgif-b2724c87872aaec55dd7e5529aa029c3108b43a5.tar.xz |
use xstrfmt to replace xmalloc + strcpy/strcat
It's easy to get manual allocation calculations wrong, and
the use of strcpy/strcat raise red flags for people looking
for buffer overflows (though in this case each site was
fine).
It's also shorter to use xstrfmt, and the printf-format
tends to be easier for a reader to see what the final string
will look like.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/fetch.c')
-rw-r--r-- | builtin/fetch.c | 9 |
1 files changed, 2 insertions, 7 deletions
diff --git a/builtin/fetch.c b/builtin/fetch.c index 55f457c04f..40d989f9ff 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1053,16 +1053,11 @@ static int fetch_one(struct remote *remote, int argc, const char **argv) refs = xcalloc(argc + 1, sizeof(const char *)); for (i = 0; i < argc; i++) { if (!strcmp(argv[i], "tag")) { - char *ref; i++; if (i >= argc) die(_("You need to specify a tag name.")); - ref = xmalloc(strlen(argv[i]) * 2 + 22); - strcpy(ref, "refs/tags/"); - strcat(ref, argv[i]); - strcat(ref, ":refs/tags/"); - strcat(ref, argv[i]); - refs[j++] = ref; + refs[j++] = xstrfmt("refs/tags/%s:refs/tags/%s", + argv[i], argv[i]); } else refs[j++] = argv[i]; } |