summaryrefslogtreecommitdiff
path: root/match-trees.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2014-06-19 17:24:33 -0400
committerJunio C Hamano <gitster@pobox.com>2014-06-19 15:20:54 -0700
commit283101869bea8feb5d58f6ea1b568e9b197526d3 (patch)
tree3aba65688e4a5a11a3d0a60d2fa60930fd398898 /match-trees.c
parent95244ae3dd49b3eed4dbfe09299b9d8847622218 (diff)
downloadgit-283101869bea8feb5d58f6ea1b568e9b197526d3.tar.gz
use xstrfmt to replace xmalloc + sprintf
This is one line shorter, and makes sure the length in the malloc and sprintf steps match. These conversions are very straightforward; we can drop the malloc entirely, and replace the sprintf with xstrfmt. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'match-trees.c')
-rw-r--r--match-trees.c9
1 files changed, 2 insertions, 7 deletions
diff --git a/match-trees.c b/match-trees.c
index e80b4af354..1ce0954a3e 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -140,17 +140,12 @@ static void match_trees(const unsigned char *hash1,
goto next;
score = score_trees(elem, hash2);
if (*best_score < score) {
- char *newpath;
- newpath = xmalloc(strlen(base) + strlen(path) + 1);
- sprintf(newpath, "%s%s", base, path);
free(*best_match);
- *best_match = newpath;
+ *best_match = xstrfmt("%s%s", base, path);
*best_score = score;
}
if (recurse_limit) {
- char *newbase;
- newbase = xmalloc(strlen(base) + strlen(path) + 2);
- sprintf(newbase, "%s%s/", base, path);
+ char *newbase = xstrfmt("%s%s/", base, path);
match_trees(elem, hash2, best_score, best_match,
newbase, recurse_limit - 1);
free(newbase);