From b2724c87872aaec55dd7e5529aa029c3108b43a5 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 19 Jun 2014 17:26:56 -0400 Subject: 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 --- sha1_name.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'sha1_name.c') diff --git a/sha1_name.c b/sha1_name.c index 2b6322fad0..5e956904b6 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -1252,10 +1252,7 @@ static void diagnose_invalid_sha1_path(const char *prefix, die("Path '%s' exists on disk, but not in '%.*s'.", filename, object_name_len, object_name); if (errno == ENOENT || errno == ENOTDIR) { - char *fullname = xmalloc(strlen(filename) - + strlen(prefix) + 1); - strcpy(fullname, prefix); - strcat(fullname, filename); + char *fullname = xstrfmt("%s%s", prefix, filename); if (!get_tree_entry(tree_sha1, fullname, sha1, &mode)) { -- cgit v1.2.3