Skip to content

Commit f438468

Browse files
committed
Avoid GNU getcwd extension behavior
GNU `getcwd` can allocate a buffer if passed `NULL` for it. This is an extension which is e.g., not recognized by clang-tidy-19's `StdCLibraryFunctions` check[^1] which emits a diagnostic on a violated precondition `buf != NULL`, ``` The 1st argument to 'getcwd' is NULL but should not be NULL [clang-analyzer-unix.StdCLibraryFunctions,-warnings-as-errors] [build] 3987 | std::unique_ptr<char, decltype(&std::free)> buffer{::getcwd(NULL, 0), std::free}; ``` This patch modifies this use of `getcwd` with this extension behavior to instead use `get_current_dir_name` which is also a GNU extension, but does not trigger this diagnostic. [^1]: https://clang.llvm.org/docs/analyzer/checkers.html#unix-stdclibraryfunctions-c
1 parent b1982f0 commit f438468

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

include/ghc/filesystem.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4229,7 +4229,7 @@ GHC_INLINE path current_path(std::error_code& ec)
42294229
}
42304230
return path(std::wstring(buffer.get()), path::native_format);
42314231
#elif defined(__GLIBC__)
4232-
std::unique_ptr<char, decltype(&std::free)> buffer { ::getcwd(NULL, 0), std::free };
4232+
std::unique_ptr<char, decltype(&std::free)> buffer { ::get_current_dir_name(), std::free };
42334233
if (buffer == nullptr) {
42344234
ec = detail::make_system_error();
42354235
return path();

0 commit comments

Comments
 (0)