OSDN Git Service

replace xstrdup(git_path(...)) with git_pathdup(...)
authorJeff King <peff@peff.net>
Thu, 20 Apr 2017 21:09:09 +0000 (17:09 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 Apr 2017 04:04:15 +0000 (21:04 -0700)
It's more efficient to use git_pathdup(), as it skips an
extra copy of the path. And by removing some calls to
git_path(), it makes it easier to audit for dangerous uses.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/config.c
fast-import.c

index 05843a0..07fcc23 100644 (file)
@@ -599,8 +599,9 @@ int cmd_config(int argc, const char **argv, const char *prefix)
                if (given_config_source.blob)
                        die("editing blobs is not supported");
                git_config(git_default_config, NULL);
-               config_file = xstrdup(given_config_source.file ?
-                                     given_config_source.file : git_path("config"));
+               config_file = given_config_source.file ?
+                               xstrdup(given_config_source.file) :
+                               git_pathdup("config");
                if (use_global_config) {
                        int fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666);
                        if (fd >= 0) {
index 4d5a7f5..d2ef8a8 100644 (file)
@@ -3203,7 +3203,7 @@ static char* make_fast_import_path(const char *path)
 {
        if (!relative_marks_paths || is_absolute_path(path))
                return xstrdup(path);
-       return xstrdup(git_path("info/fast-import/%s", path));
+       return git_pathdup("info/fast-import/%s", path);
 }
 
 static void option_import_marks(const char *marks,