path: root/shell.c
diff options
authorJeff King <>2014-06-19 21:26:56 (GMT)
committerJunio C Hamano <>2014-06-19 22:20:54 (GMT)
commitb2724c87872aaec55dd7e5529aa029c3108b43a5 (patch)
tree905e0c855f087699b8a5fd8054271a8e7c5d9dad /shell.c
parent283101869bea8feb5d58f6ea1b568e9b197526d3 (diff)
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 <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'shell.c')
1 files changed, 1 insertions, 5 deletions
diff --git a/shell.c b/shell.c
index 5c0d47a..ace62e4 100644
--- a/shell.c
+++ b/shell.c
@@ -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)