Fixed #7961 (Hang in CheckOther::checkFuncArgNamesDifferent)

This commit is contained in:
Daniel Marjamäki 2017-03-24 22:01:05 +01:00
parent 5fb0f46a3a
commit f5d56fd303
2 changed files with 15 additions and 15 deletions

View File

@ -2819,22 +2819,22 @@ void CheckOther::checkFuncArgNamesDifferent()
definitions[j] = variable->nameToken();
}
// get the declaration (search for first token with varId)
bool skip = false;
while (decl && !Token::Match(decl, ",|)|;")) {
// skip everything after the assignment because
// it could also have a varId or be the first
// token with a varId if there is no name token
if (decl->str() == "=")
skip = true;
// skip over template
else if (decl->link())
decl = decl->link();
else if (!skip && decl->varId()) {
declarations[j] = decl;
if (decl->str() == "=") {
decl = decl->nextArgument();
break;
}
// skip over template
if (decl->link())
decl = decl->link();
else if (decl->varId())
declarations[j] = decl;
decl = decl->next();
}
if (decl)
if (Token::simpleMatch(decl, ","))
decl = decl->next();
}
// check for different argument order
@ -2866,19 +2866,19 @@ void CheckOther::checkFuncArgNamesDifferent()
}
}
void CheckOther::funcArgNamesDifferent(const std::string & name, size_t index,
void CheckOther::funcArgNamesDifferent(const std::string & functionName, size_t index,
const Token* declaration, const Token* definition)
{
std::list<const Token *> tokens;
tokens.push_back(declaration);
tokens.push_back(definition);
reportError(tokens, Severity::style, "funcArgNamesDifferent",
"Function '" + name + "' argument " + MathLib::toString(index + 1) + " names different: declaration '" +
"Function '" + functionName + "' argument " + MathLib::toString(index + 1) + " names different: declaration '" +
(declaration ? declaration->str() : std::string("A")) + "' definition '" +
(definition ? definition->str() : std::string("B")) + "'.", CWE(0U), true);
}
void CheckOther::funcArgOrderDifferent(const std::string & name,
void CheckOther::funcArgOrderDifferent(const std::string & functionName,
const Token* declaration, const Token* definition,
const std::vector<const Token *> & declarations,
const std::vector<const Token *> & definitions)
@ -2886,7 +2886,7 @@ void CheckOther::funcArgOrderDifferent(const std::string & name,
std::list<const Token *> tokens;
tokens.push_back(declarations.size() ? declarations[0] ? declarations[0] : declaration : nullptr);
tokens.push_back(definitions.size() ? definitions[0] ? definitions[0] : definition : nullptr);
std::string msg = "Function '" + name + "' argument order different: declaration '";
std::string msg = "Function '" + functionName + "' argument order different: declaration '";
for (std::size_t i = 0; i < declarations.size(); ++i) {
if (i != 0)
msg += ", ";

View File

@ -262,8 +262,8 @@ private:
void unknownEvaluationOrder(const Token* tok);
static bool isMovedParameterAllowedForInconclusiveFunction(const Token * tok);
void accessMovedError(const Token *tok, const std::string &varname, ValueFlow::Value::MoveKind moveKind, bool inconclusive);
void funcArgNamesDifferent(const std::string & name, size_t index, const Token* declaration, const Token* definition);
void funcArgOrderDifferent(const std::string & name, const Token * declaration, const Token * definition, const std::vector<const Token*> & declarations, const std::vector<const Token*> & definitions);
void funcArgNamesDifferent(const std::string & functionName, size_t index, const Token* declaration, const Token* definition);
void funcArgOrderDifferent(const std::string & functionName, const Token * declaration, const Token * definition, const std::vector<const Token*> & declarations, const std::vector<const Token*> & definitions);
void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const {
CheckOther c(nullptr, settings, errorLogger);