From: Linus Torvalds <[email protected]>
Date: Sat, 24 Jan 2015 12:56:34 +1200
Subject: [PATCH 4/5] 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 <[email protected]>
---
 git-access.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/git-access.c b/git-access.c
index 3b01623b9897..1c9a402ba367 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);
-- 
2.3.0.rc2.2.g0d1c285

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to