[clang] [clang-installapi] ] Fix potential null pointer dereference in file enumeration (PR #97900)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 30 07:41:00 PDT 2024


================
@@ -51,8 +51,14 @@ llvm::Expected<PathSeq> enumerateFiles(FileManager &FM, StringRef Directory) {
     if (EC)
       return errorCodeToError(EC);
 
+    // Ensure the iterator is valid before dereferencing.
+    if (i == ie)
+      break;
+
     // Skip files that do not exist. This usually happens for broken symlinks.
-    if (FS.status(i->path()) == std::errc::no_such_file_or_directory)
+    auto StatusOrErr = FS.status(i->path());
+    if (!StatusOrErr ||
----------------
smanna12 wrote:

Doing more investigation, it looks like a false positive hit by static analyzer tool. closing this PR. 

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


More information about the cfe-commits mailing list