Commit b254a5856589e06d5ef66bfb7c7b2127249f440e

Patrick Steinhardt 2020-09-18T10:43:34

sysdir: fix formatting error message with NULL string When trying to the template dir, we pass in a `NULL` pointer for the filename. That's perfectly fine, but if we're failing to find the template directory then we'll creat an error message with the `NULL` pointer passed in. Fix the issue by setting different error messages based on whether the filename is given or not. This even makes sense, as we're not searching for a file in case we have no `name`, but for a directory. So the error would've been misleading anyway.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
diff --git a/src/sysdir.c b/src/sysdir.c
index bcef97c..6dc78c8 100644
--- a/src/sysdir.c
+++ b/src/sysdir.c
@@ -298,8 +298,11 @@ static int git_sysdir_find_in_dirlist(
 	}
 
 done:
+	if (name)
+		git_error_set(GIT_ERROR_OS, "the %s file '%s' doesn't exist", label, name);
+	else
+		git_error_set(GIT_ERROR_OS, "the %s directory doesn't exist", label);
 	git_buf_dispose(path);
-	git_error_set(GIT_ERROR_OS, "the %s file '%s' doesn't exist", label, name);
 	return GIT_ENOTFOUND;
 }