[clang] Improve modeling of two functions in StdLibraryFunctionsChecker (PR #78079)
Balázs Kéri via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 16 02:09:43 PST 2024
================
@@ -248,3 +248,25 @@ void check_fflush_all(void) {
if (errno) {} // no-warning
}
}
+
+void check_opendir(const char *Path) {
+ DIR *Dir = opendir(Path);
+ if (Dir == NULL) {
+ clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+ if (errno) {} // no-warning
+ } else {
+ if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}}
+ closedir(Dir);
+ }
+}
+
+void check_fdopendir(int Fd) {
+ DIR *Dir = fdopendir(Fd);
+ if (Dir == NULL) {
+ clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+ if (errno) {} // no-warning
+ } else {
+ if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}}
+ closedir(Dir);
+ }
+}
----------------
balazske wrote:
They need no tests like there is no test for `chdir`, `chown`, `close`, `open`, and all other functions in the checker. These `DIR` type functions are not more special than the others. It can be possible to add these `errno` tests for all of the functions in a separate file and in a generated way. The tests in **stream_*** files are related to `StreamChecker`, but not the `DIR` functions. (Goal of `StreamChecker` is now only to work with the functions with `FILE*` argument.)
https://github.com/llvm/llvm-project/pull/78079
More information about the cfe-commits
mailing list