fs_path: exit quickly in `dirname_r` failure When we encounter a situation where we need to exit, simply `return -1` instead of trying to set `len = -1` and then jumping to the exit handler, which would erroneously do work based on the `len` value.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
diff --git a/src/util/fs_path.c b/src/util/fs_path.c
index 920c390..6584242 100644
--- a/src/util/fs_path.c
+++ b/src/util/fs_path.c
@@ -109,7 +109,7 @@ int git_fs_path_basename_r(git_str *buffer, const char *path)
/* Empty or NULL string gets treated as "." */
if (path == NULL || *path == '\0') {
startp = ".";
- len = 1;
+ len = 1;
goto Exit;
}
@@ -121,7 +121,7 @@ int git_fs_path_basename_r(git_str *buffer, const char *path)
/* All slashes becomes "/" */
if (endp == path && *endp == '/') {
startp = "/";
- len = 1;
+ len = 1;
goto Exit;
}
@@ -193,8 +193,7 @@ int git_fs_path_dirname_r(git_str *buffer, const char *path)
if (endp - path + 1 > INT_MAX) {
git_error_set(GIT_ERROR_INVALID, "path too long");
- len = -1;
- goto Exit;
+ return -1;
}
if ((len = win32_prefix_length(path, (int)(endp - path + 1))) > 0) {
@@ -219,8 +218,7 @@ int git_fs_path_dirname_r(git_str *buffer, const char *path)
if (endp - path + 1 > INT_MAX) {
git_error_set(GIT_ERROR_INVALID, "path too long");
- len = -1;
- goto Exit;
+ return -1;
}
if ((len = win32_prefix_length(path, (int)(endp - path + 1))) > 0) {