Commit a76d75021c50315ab52d7a4e60419dc2e64c47e9

Patrick Steinhardt 2017-03-28T09:12:34

path: short-circuit `git_path_apply_relative` on error Short-circuit the call to `git_path_resolve_relative` in case `git_buf_joinpath` returns an error. While this does not fix any immediate errors, the resulting code is easier to read and handles potential new error conditions raised by `git_buf_joinpath`.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
diff --git a/src/path.c b/src/path.c
index 9b15c8c..b7205a6 100644
--- a/src/path.c
+++ b/src/path.c
@@ -826,8 +826,8 @@ int git_path_resolve_relative(git_buf *path, size_t ceiling)
 
 int git_path_apply_relative(git_buf *target, const char *relpath)
 {
-	git_buf_joinpath(target, git_buf_cstr(target), relpath);
-	return git_path_resolve_relative(target, 0);
+	return git_buf_joinpath(target, git_buf_cstr(target), relpath) ||
+	    git_path_resolve_relative(target, 0);
 }
 
 int git_path_cmp(