summaryrefslogtreecommitdiff
path: root/builtin/apply.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2014-06-19 21:26:56 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-06-19 22:20:54 (GMT)
commitb2724c87872aaec55dd7e5529aa029c3108b43a5 (patch)
tree905e0c855f087699b8a5fd8054271a8e7c5d9dad /builtin/apply.c
parent283101869bea8feb5d58f6ea1b568e9b197526d3 (diff)
downloadgit-b2724c87872aaec55dd7e5529aa029c3108b43a5.zip
git-b2724c87872aaec55dd7e5529aa029c3108b43a5.tar.gz
git-b2724c87872aaec55dd7e5529aa029c3108b43a5.tar.bz2
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/apply.c')
-rw-r--r--builtin/apply.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/builtin/apply.c b/builtin/apply.c
index 9c5724e..b796910 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -1281,9 +1281,7 @@ static int parse_git_header(const char *line, int len, unsigned int size, struct
*/
patch->def_name = git_header_name(line, len);
if (patch->def_name && root) {
- char *s = xmalloc(root_len + strlen(patch->def_name) + 1);
- strcpy(s, root);
- strcpy(s + root_len, patch->def_name);
+ char *s = xstrfmt("%s%s", root, patch->def_name);
free(patch->def_name);
patch->def_name = s;
}