[PR49761] Fix variadic arg handling in matcher

Mishandling of variadic arguments in a function call caused a crash
(runtime assert fail) in bugprone-infinite-loop tidy checker.  Fix
is to limit argument matching to the lesser of the number of variadic
params in the prototype or the number of actual args in the call.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D101108
This commit is contained in:
Chris Hamilton 2021-04-22 15:39:36 -05:00 committed by eahcmrh
parent 10b781fb03
commit cae3b70ceb
2 changed files with 19 additions and 1 deletions

View File

@ -386,3 +386,18 @@ void evaluatable(bool CondVar) {
do {
} while (false && CondVar);
}
struct logger {
void (*debug)(struct logger *, const char *, ...);
};
int foo(void) {
struct logger *pl = 0;
int iterator = 0;
while (iterator < 10) {
char *l_tmp_msg = 0;
pl->debug(pl, "%d: %s\n", iterator, l_tmp_msg);
iterator++;
}
return 0;
}

View File

@ -4757,8 +4757,11 @@ AST_POLYMORPHIC_MATCHER_P2(forEachArgumentWithParamType,
int ParamIndex = 0;
bool Matched = false;
unsigned NumArgs = Node.getNumArgs();
if (FProto && FProto->isVariadic())
NumArgs = std::min(NumArgs, FProto->getNumParams());
for (; ArgIndex < Node.getNumArgs(); ++ArgIndex, ++ParamIndex) {
for (; ArgIndex < NumArgs; ++ArgIndex, ++ParamIndex) {
BoundNodesTreeBuilder ArgMatches(*Builder);
if (ArgMatcher.matches(*(Node.getArg(ArgIndex)->IgnoreParenCasts()), Finder,
&ArgMatches)) {