Commit 9f0088c4 by Edward Thomson

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.
parent 043a87a0
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment