From 21a5f4ec1120b5ae53e2238f8f9e50bb549b2c4d Mon Sep 17 00:00:00 2001 From: K Jayatheerth Date: Mon, 2 Mar 2026 19:51:36 +0530 Subject: [PATCH 1/3] path: remove unused header The "environment.h" header is included in "path.c", but none of the functions or macros it provides are used in this file. Signed-off-by: K Jayatheerth Signed-off-by: Junio C Hamano --- path.c | 1 - 1 file changed, 1 deletion(-) diff --git a/path.c b/path.c index d726537622..f613d8bbd1 100644 --- a/path.c +++ b/path.c @@ -4,7 +4,6 @@ #include "git-compat-util.h" #include "abspath.h" -#include "environment.h" #include "gettext.h" #include "repository.h" #include "strbuf.h" From 68c14c2a03cd0d895d27309d0437bf745ed6b7c3 Mon Sep 17 00:00:00 2001 From: K Jayatheerth Date: Mon, 2 Mar 2026 19:51:37 +0530 Subject: [PATCH 2/3] path: use the right datatype The strlen() function returns a size_t Storing this in a standard signed int is a bad practice that invites overflow vulnerabilities if paths get absurdly long. Signed-off-by: K Jayatheerth Signed-off-by: Junio C Hamano --- path.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/path.c b/path.c index f613d8bbd1..56be5e1726 100644 --- a/path.c +++ b/path.c @@ -58,7 +58,7 @@ static void strbuf_cleanup_path(struct strbuf *sb) static int dir_prefix(const char *buf, const char *dir) { - int len = strlen(dir); + size_t len = strlen(dir); return !strncmp(buf, dir, len) && (is_dir_sep(buf[len]) || buf[len] == '\0'); } From c815ab0acd9bb3f767a87d7096b872b341a91ddd Mon Sep 17 00:00:00 2001 From: K Jayatheerth Date: Mon, 2 Mar 2026 19:51:38 +0530 Subject: [PATCH 3/3] path: remove redundant function calls We fetch the exact same setting up to four times. We fix this by evaluating it once, storing it in a local variable, and referencing that variable. Signed-off-by: K Jayatheerth Signed-off-by: Junio C Hamano --- path.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/path.c b/path.c index 56be5e1726..5cd38b2a16 100644 --- a/path.c +++ b/path.c @@ -741,18 +741,18 @@ int calc_shared_perm(struct repository *repo, int mode) { int tweak; - - if (repo_settings_get_shared_repository(repo) < 0) - tweak = -repo_settings_get_shared_repository(repo); + int shared_repo = repo_settings_get_shared_repository(repo); + if (shared_repo < 0) + tweak = -shared_repo; else - tweak = repo_settings_get_shared_repository(repo); + tweak = shared_repo; if (!(mode & S_IWUSR)) tweak &= ~0222; if (mode & S_IXUSR) /* Copy read bits to execute bits */ tweak |= (tweak & 0444) >> 2; - if (repo_settings_get_shared_repository(repo) < 0) + if (shared_repo < 0) mode = (mode & ~0777) | tweak; else mode |= tweak;