[clang] [-Wunsafe-buffer-usage] Allow strerror for %s in printf-like calls (PR #175208)

Oliver Hunt via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 12 15:03:55 PST 2026


================
@@ -771,6 +771,11 @@ static bool isNullTermPointer(const Expr *Ptr, ASTContext &Ctx) {
       if (MD->getName() == "c_str" && RD->getName() == "basic_string")
         return true;
   }
+  if (auto *CE = dyn_cast<CallExpr>(Ptr->IgnoreParenImpCasts())) {
+    const FunctionDecl *F = CE->getDirectCallee();
+    if (F && F->getIdentifier() && F->getName() == "strerror")
----------------
ojhunt wrote:

That's part of the -fbounds-safety type information, it's the type system representation "this is a pointer to a sentinel terminated buffer" of the `__terminated_by` (probably wrong spelling) attribute. So a string literal has a semantically something like `ValueTerminatedType { sentinel: 0 }`, my *understanding* is that it will prevent something like `ptr++` walking past the terminator.

In this case however we'd just be interested in it from the view of confirming the buffer is terminated.

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


More information about the cfe-commits mailing list