From b770d0a6b71c1807469d268f8572bd31395d894b Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sat, 24 Jan 2015 12:56:34 +1200 Subject: git-access: use the new format_string helpers It may be a bit less efficient to use a printf-style interface rather than the explicit malloc and memcpy, but the code ends up simpler and more readable. Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- git-access.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/git-access.c b/git-access.c index 3b01623b9..1c9a402ba 100644 --- a/git-access.c +++ b/git-access.c @@ -49,19 +49,15 @@ struct git_repository *is_git_repository(const char *filename, const char **bran * to generate proper error messages. */ *branchp = filename; - loc = malloc(flen+1); + loc = format_string("%.*s", flen, filename); if (!loc) return dummy_git_repository; - memcpy(loc, filename, flen); - loc[flen] = 0; - branch = malloc(blen+1); + branch = format_string("%.*s", blen, filename+flen+1); if (!branch) { free(loc); return dummy_git_repository; } - memcpy(branch, filename+flen+1, blen); - branch[blen] = 0; if (stat(loc, &st) < 0 || !S_ISDIR(st.st_mode)) { free(loc); -- cgit v1.2.3-70-g09d2