From fc110202dffa06950716e0cc4535b07aaa2c439c Mon Sep 17 00:00:00 2001 From: Rahul Joshi Date: Thu, 29 Aug 2024 08:00:25 -0700 Subject: [Support] Validate number of arguments passed to formatv() (#105745) Change formatv() to validate that the number of arguments passed matches number of replacement fields in the format string, and that the replacement indices do not contain holes. To support cases where this cannot be guaranteed, introduce a formatv() overload that allows disabling validation with a bool flag as its first argument. --- clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp') diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp index 8f4bd17..4f30b2a 100644 --- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp @@ -1401,7 +1401,10 @@ void StdLibraryFunctionsChecker::checkPostCall(const CallEvent &Call, ErrnoNote = llvm::formatv("After calling '{0}' {1}", FunctionName, ErrnoNote); } else { - CaseNote = llvm::formatv(Case.getNote().str().c_str(), FunctionName); + // Disable formatv() validation as the case note may not always have the + // {0} placeholder for function name. + CaseNote = + llvm::formatv(false, Case.getNote().str().c_str(), FunctionName); } const SVal RV = Call.getReturnValue(); -- cgit v1.1