summaryrefslogtreecommitdiffstats
path: root/git-access.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2015-01-24 12:56:34 +1200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-02-15 06:03:30 -0800
commitb770d0a6b71c1807469d268f8572bd31395d894b (patch)
treeb215c92f838312459e15fbb6d15744a18e2a54f9 /git-access.c
parente287590e4b70cbe9ee6e80bbaf81feb79e464dac (diff)
downloadsubsurface-b770d0a6b71c1807469d268f8572bd31395d894b.tar.gz
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 <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'git-access.c')
-rw-r--r--git-access.c8
1 files 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);