From f5d56fd3037afab6bf4691b56b130407e11e4dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 24 Mar 2017 22:01:05 +0100 Subject: [PATCH] Fixed #7961 (Hang in CheckOther::checkFuncArgNamesDifferent) --- lib/checkother.cpp | 26 +++++++++++++------------- lib/checkother.h | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index fd9dc2501..c7a9fe264 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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 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 & declarations, const std::vector & definitions) @@ -2886,7 +2886,7 @@ void CheckOther::funcArgOrderDifferent(const std::string & name, std::list 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 += ", "; diff --git a/lib/checkother.h b/lib/checkother.h index 6033ba954..39d8c5548 100644 --- a/lib/checkother.h +++ b/lib/checkother.h @@ -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 & declarations, const std::vector & 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 & declarations, const std::vector & definitions); void getErrorMessages(ErrorLogger *errorLogger, const Settings *settings) const { CheckOther c(nullptr, settings, errorLogger);