[clang] [clang][analyzer] Improve modeling of 'popen' and 'pclose' in StdLibraryFunctionsChecker (PR #78895)

Ben Shi via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 23 17:40:09 PST 2024


================
@@ -51,6 +51,17 @@ void check_freopen(void) {
   if (errno) {} // expected-warning{{An undefined value may be read from 'errno'}}
 }
 
+void check_popen(void) {
+  FILE *F = popen("xxx", "r");
+  if (!F) {
+    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' [unix.Errno]}}
+    pclose(F);
+  }
+}
+
----------------
benshi001 wrote:

I have put these tests to `errno-stdlibraryfunctions.c`, which seems better, since tests in `std-c-library-functions-POSIX.c` do not involve `errno`.

https://github.com/llvm/llvm-project/pull/78895


More information about the cfe-commits mailing list