-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid GNU getcwd
extension behavior
#188
Avoid GNU getcwd
extension behavior
#188
Conversation
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
centos7 has reached EOL on 2024-06-30, centos8 on 2021-10-31. In practical terms this means that their package repositories are offline for the foreseeable future and the CI tasks making use of them might never run again. This patch replaces the existing CI jobs on centos7/centos8 with jobs on rockylinux8/9. Since rockylinux is an open source variant similar to RHEL this should provide testing with similar spirit. In contrast to centos, rockylinux does provide very granular tagging of releases which if used would help avoid breaking on e.g., subtle package changes in their package repositories. I however did not use very precise tags in the patch and instead went with broad "trains" for the 8 and 9 series; I hope this minimizes maintenance overhead (e.g., bumping to new releases) while still giving a good testing signal.
I added a commit switching from centos CI over to rockylinux (latest two releases). Let me know whether you would like me to pull that into a separate PR. |
@gulrak, anything I could do to pique your interest in this patch? I am having trouble suppressing it in my clang-tidy setup, but would prefer keeping the check globally enabled. An alternative approach would be to suppress the check for just this line (I see that there are already some suppression in this project), e.g., by prefixing it with // NOLINTNEXTLINE(clang-analyzer-unix.StdCLibraryFunctions) |
Sorry, for me not reacting quicker, but you are right, that is a better solution. I was, for a moment, thinking if one might switch to something along the lines (but slightly to be adapted) of the no extension needing suggested code snippet from the documentation, like char *
gnu_getcwd ()
{
size_t size = 100;
while (1)
{
char *buffer = (char *) xmalloc (size);
if (getcwd (buffer, size) == buffer)
return buffer;
free (buffer);
if (errno != ERANGE)
return 0;
size *= 2;
}
} But on the base that it currently uses the extensions, I think your solution is a quick and easy one, and I'm all for not having exceptions in tidy. I'm at work currently, but will merge it later today. Thanks for the PR and the nagging. ;-) |
GNU
getcwd
can allocate a buffer if passedNULL
for it. This is an extension which is e.g., not recognized by clang-tidy-19'sStdCLibraryFunctions
check1 which emits a diagnostic on a violated preconditionbuf != NULL
,This patch modifies this use of
getcwd
with this extension behavior to instead useget_current_dir_name
which is also a GNU extension, but does not trigger this diagnostic.Footnotes
https://clang.llvm.org/docs/analyzer/checkers.html#unix-stdclibraryfunctions-c ↩