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

Balázs Kéri via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 23 02:40:34 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);
+  }
+}
+
----------------
balazske wrote:

I like more if these new tests go into file **std-c-library-functions-POSIX.c**, unless the functions will be added to `StreamChecker` too. It looks like that the API has the same usage for files returned by `popen`, so `popen` (and `pclose`) can be added to `StreamChecker`.

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


More information about the cfe-commits mailing list