[clang] [clang][analyzer] Improve 'errno' modeling of 'mkdtemp' (PR #76671)
Balázs Kéri via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 3 01:03:18 PST 2024
================
@@ -54,3 +51,25 @@ int errno_lseek(int fildes, off_t offset) {
}
return 0;
}
+
+void errno_mkstemp(char *template) {
+ int FD = mkstemp(template);
+ if (FD >= 0) {
+ if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}}
+ close(FD);
+ } else {
+ clang_analyzer_eval(FD == -1); // expected-warning{{TRUE}}
+ clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+ if (errno) {} // no warning
+ }
+}
+
+void errno_mkdtemp(char *template) {
+ char *Dir = mkdtemp(template);
+ if (Dir == NULL) {
+ clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
+ if (errno) {} // no warning
+ } else {
----------------
balazske wrote:
```suggestion
} else {
`clang_analyzer_eval(Dir == template); // expected-warning{{TRUE}}`
```
https://github.com/llvm/llvm-project/pull/76671
More information about the cfe-commits
mailing list