[clang] [Clang] Added clang diagnostic when snprintf/vsnprintf uses sizeof(de… (PR #170637)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 19 05:56:59 PST 2025
================
@@ -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:
This makes sure that warnings are written if a cast is used in the dest parameter(e.g '(char *)dest' ).
I added this since gcc outputs diagnostics for this case. [Example code](https://godbolt.org/z/8dqYfoaYW)
https://github.com/llvm/llvm-project/pull/170637
More information about the cfe-commits
mailing list