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>
This commit is contained in:
Jeff King
2014-06-19 17:26:56 -04:00
committed by Junio C Hamano
parent 283101869b
commit b2724c8787
5 changed files with 6 additions and 23 deletions

View File

@ -46,11 +46,7 @@ static int is_valid_cmd_name(const char *cmd)
static char *make_cmd(const char *prog)
{
char *prefix = xmalloc((strlen(prog) + strlen(COMMAND_DIR) + 2));
strcpy(prefix, COMMAND_DIR);
strcat(prefix, "/");
strcat(prefix, prog);
return prefix;
return xstrfmt("%s/%s", COMMAND_DIR, prog);
}
static void cd_to_homedir(void)