[clang] [Clang][-Wunsafe-buffer-usage] Allow safe form of libc memset. (PR #178107)
Ziqing Luo via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 28 16:51:04 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")
----------------
ziqingluo-90 wrote:
It should not.
https://github.com/rohanjr/llvm-project/blob/92543d3123f8d22840bafa6ae85827b916416d90/clang/lib/Analysis/UnsafeBufferUsage.cpp#L2227
Only `std::memset` and `memset` declared in file scope.
https://github.com/llvm/llvm-project/pull/178107
More information about the cfe-commits
mailing list