[clang] [Clang][-Wunsafe-buffer-usage] Allow safe form of libc memset. (PR #178107)
Florian Mayer via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 28 11:10:50 PST 2026
================
@@ -1105,6 +1144,36 @@ static bool isPredefinedUnsafeLibcFunc(const FunctionDecl &Node) {
return Name.ends_with("scanf");
}
+// Returns true if this is an unsafe call to `memset`.
+// The only call we currently consider safe is of the form
+// `memset(&x, 0, sizeof(x))`, with possible variations in parentheses.
+static bool isUnsafeMemset(const CallExpr &Node, ASTContext &Ctx) {
+ const FunctionDecl *FD = Node.getDirectCallee();
+ assert(FD && "It should have been checked that FD is non-null.");
+
+ const IdentifierInfo *II = FD->getIdentifier();
+ if (!II || II->getName() != "memset")
----------------
fmayer wrote:
What if I create `my_namespace::memset` and `using my_namespace::memset`, does this match?
https://github.com/llvm/llvm-project/pull/178107
More information about the cfe-commits
mailing list