[clang] [Clang] Optimize -Wunsafe-buffer-usage. (PR #125492)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 7 03:49:41 PST 2025


================
@@ -839,17 +988,22 @@ AST_MATCHER_P(CallExpr, hasUnsafePrintfStringArg,
       // second is an integer, it is a snprintf:
       const Expr *UnsafeArg;
 
-      if (hasUnsafeFormatOrSArg(&Node, UnsafeArg, 2, Ctx, false))
-        return UnsafeStringArgMatcher.matches(*UnsafeArg, Finder, Builder);
+      if (hasUnsafeFormatOrSArg(&Node, UnsafeArg, 2, Ctx, false)) {
+        Result.addNode(Op, DynTypedNode::create(*UnsafeArg));
+        return true;
+      }
       return false;
     }
   }
   // We don't really recognize this "normal" printf, the only thing we
   // can do is to require all pointers to be null-terminated:
-  for (auto Arg : Node.arguments())
-    if (Arg->getType()->isPointerType() && !isNullTermPointer(Arg))
-      if (UnsafeStringArgMatcher.matches(*Arg, Finder, Builder))
+  for (const auto *Arg : Node.arguments())
+    if (Arg->getType()->isPointerType() && !isNullTermPointer(Arg)) {
+      if (isa<Expr>(Arg)) {
----------------
ilya-biryukov wrote:

NIT: isn't this check redundant? I believe Arg should already be `Expr*`.

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


More information about the cfe-commits mailing list