Skip to content

Commit 9f0088c

Browse files
committed
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 parent 043a87a commit 9f0088c

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/util/fs_path.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ int git_fs_path_basename_r(git_str *buffer, const char *path)
109109
/* Empty or NULL string gets treated as "." */
110110
if (path == NULL || *path == '\0') {
111111
startp = ".";
112-
len = 1;
112+
len = 1;
113113
goto Exit;
114114
}
115115

@@ -121,7 +121,7 @@ int git_fs_path_basename_r(git_str *buffer, const char *path)
121121
/* All slashes becomes "/" */
122122
if (endp == path && *endp == '/') {
123123
startp = "/";
124-
len = 1;
124+
len = 1;
125125
goto Exit;
126126
}
127127

@@ -193,8 +193,7 @@ int git_fs_path_dirname_r(git_str *buffer, const char *path)
193193

194194
if (endp - path + 1 > INT_MAX) {
195195
git_error_set(GIT_ERROR_INVALID, "path too long");
196-
len = -1;
197-
goto Exit;
196+
return -1;
198197
}
199198

200199
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)
219218

220219
if (endp - path + 1 > INT_MAX) {
221220
git_error_set(GIT_ERROR_INVALID, "path too long");
222-
len = -1;
223-
goto Exit;
221+
return -1;
224222
}
225223

226224
if ((len = win32_prefix_length(path, (int)(endp - path + 1))) > 0) {

0 commit comments

Comments
 (0)