[clang] [Clang] Added clang diagnostic when snprintf/vsnprintf uses sizeof(de… (PR #170637)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 20 03:57:24 PST 2026
================
@@ -1451,6 +1451,8 @@ void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
DestinationSize = ComputeSizeArgument(0);
const Expr *LenArg = TheCall->getArg(1)->IgnoreParenImpCasts();
const Expr *Dest = TheCall->getArg(0)->IgnoreParenImpCasts();
+ if (const auto *DestCast = dyn_cast_or_null<CastExpr>(Dest))
+ Dest = DestCast->getSubExprAsWritten();
----------------
BgZun wrote:
Now looking at it using`IgnoreParenImplCasts` might be a problem. Since if we use something like `snprintf((char*)(char*)a,sizeof(a),...)` no warning will be printed. It might be better to use `IgnoreCasts` instead
https://github.com/llvm/llvm-project/pull/170637
More information about the cfe-commits
mailing list