[clang] [Clang][Sema] Add fortify warnings for vsprintf (PR #230672)
George Burgess IV via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 13 10:52:05 PDT 2026
================
@@ -1406,9 +1406,17 @@ void Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
}
case Builtin::BIsprintf:
- case Builtin::BI__builtin___sprintf_chk: {
- size_t FormatIndex = BuiltinID == Builtin::BIsprintf ? 1 : 3;
- auto *FormatExpr = TheCall->getArg(FormatIndex)->IgnoreParenImpCasts();
+ case Builtin::BI__builtin_sprintf:
+ case Builtin::BI__builtin___sprintf_chk:
+ case Builtin::BIvsprintf:
+ case Builtin::BI__builtin_vsprintf:
+ case Builtin::BI__builtin___vsprintf_chk: {
+ bool IsChk = BuiltinID == Builtin::BI__builtin___sprintf_chk ||
+ BuiltinID == Builtin::BI__builtin___vsprintf_chk;
+ std::optional<unsigned> FormatIndex = Checker.TranslateIndex(IsChk ? 3 : 1);
+ if (!FormatIndex)
+ return;
+ auto *FormatExpr = TheCall->getArg(*FormatIndex)->IgnoreParenImpCasts();
----------------
gburgessiv wrote:
nit: i understand it's the way this was previously written, but please `const auto *` while we're here - makes it a bit clearer that we don't need a mutable pointee
https://github.com/llvm/llvm-project/pull/230672
More information about the cfe-commits
mailing list