[clang] [Clang][Sema] Add fortify warnings for realpath (PR #230695)

via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 16 06:48:09 PDT 2026


================
@@ -1601,6 +1601,23 @@ void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
     BufferSize = Checker.ComputeSizeArgument(0);
     break;
   }
+  case Builtin::BIrealpath: {
+    BufferSize = Checker.ComputeSizeArgument(1);
+    if (!BufferSize)
+      return;
+    const llvm::Triple &T = Context.getTargetInfo().getTriple();
+    uint64_t PathMax = 0;
+    if (T.isOSLinux() || T.isOSFuchsia() || T.isOSAIX() || T.isOSHaiku())
+      PathMax = 4096;
+    else if (T.isOSDarwin() || T.isOSFreeBSD() || T.isOSNetBSD() ||
+             T.isOSOpenBSD() || T.isOSSolaris())
+      PathMax = 1024;
+    else
+      return;
----------------
enh-google wrote:

> Keeping the diagnostic wording focused on the non-null buffer's size ("at least %2 bytes are required") rather than suggesting NULL also avoids @enh-google's point about targets/OS versions where realpath(path, NULL) may not be supported.

i know why you went that way, but to be clear: "callers should prefer null, and suggesting null is better advice".

does anyone actually care about systems that don't even support this posix 2008 requirement?

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


More information about the cfe-commits mailing list