Fix Cppcheck warnings about mismatching function argument names

This commit is contained in:
Daniel Marjamäki 2017-04-01 09:31:27 +02:00
parent 35d1479d05
commit 633ed23c0d
13 changed files with 71 additions and 71 deletions

View File

@ -90,9 +90,9 @@ public:
static void reportStatus(std::size_t fileindex, std::size_t filecount, std::size_t sizedone, std::size_t sizetotal); static void reportStatus(std::size_t fileindex, std::size_t filecount, std::size_t sizedone, std::size_t sizetotal);
/** /**
* @param fp Output file * @param exception_output Output file
*/ */
static void setExceptionOutput(FILE* fp); static void setExceptionOutput(FILE* exception_output);
/** /**
* @return file name to be used for output from exception handler. Has to be either "stdout" or "stderr". * @return file name to be used for output from exception handler. Has to be either "stdout" or "stderr".
*/ */

View File

@ -43,7 +43,7 @@ class Settings;
*/ */
class ThreadExecutor : public ErrorLogger { class ThreadExecutor : public ErrorLogger {
public: public:
ThreadExecutor(const std::map<std::string, std::size_t> &files, Settings &settings, ErrorLogger &_errorLogger); ThreadExecutor(const std::map<std::string, std::size_t> &files, Settings &settings, ErrorLogger &errorLogger);
virtual ~ThreadExecutor(); virtual ~ThreadExecutor();
unsigned int check(); unsigned int check();

View File

@ -12,7 +12,7 @@ class LibraryEditArgDialog : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
LibraryEditArgDialog(QWidget *parent, const CppcheckLibraryData::Function::Arg &a); LibraryEditArgDialog(QWidget *parent, const CppcheckLibraryData::Function::Arg &arg);
~LibraryEditArgDialog(); ~LibraryEditArgDialog();
CppcheckLibraryData::Function::Arg getArg() const; CppcheckLibraryData::Function::Arg getArg() const;

View File

@ -332,16 +332,16 @@ private:
/** /**
* @brief Load XML file to the GUI. * @brief Load XML file to the GUI.
* @param file Filename (inc. path) of XML file to load. * @param selectedFile Filename (inc. path) of XML file to load.
*/ */
void LoadResults(const QString file); void LoadResults(const QString selectedFile);
/** /**
* @brief Load XML file to the GUI. * @brief Load XML file to the GUI.
* @param file Filename (inc. path) of XML file to load. * @param selectedFile Filename (inc. path) of XML file to load.
* @param checkedDirectory Path to the directory that the results were generated for. * @param sourceDirectory Path to the directory that the results were generated for.
*/ */
void LoadResults(const QString file, const QString checkedDirectory); void LoadResults(const QString selectedFile, const QString sourceDirectory);
/** /**
* @brief Load project file to the GUI. * @brief Load project file to the GUI.

View File

@ -49,7 +49,7 @@ public:
void assertWithSideEffects(); void assertWithSideEffects();
protected: protected:
void checkVariableAssignment(const Token* tmp, const Scope *assertionScope); void checkVariableAssignment(const Token* assignTok, const Scope *assertionScope);
static bool inSameScope(const Token* returnTok, const Token* assignTok); static bool inSameScope(const Token* returnTok, const Token* assignTok);
private: private:

View File

@ -1788,17 +1788,17 @@ CheckBufferOverrun::ArrayInfo::ArrayInfo()
{ {
} }
CheckBufferOverrun::ArrayInfo::ArrayInfo(const Variable *var, const SymbolDatabase * symDb, const unsigned int forcedeclid) CheckBufferOverrun::ArrayInfo::ArrayInfo(const Variable *var, const SymbolDatabase * symbolDatabase, const unsigned int forcedeclid)
: _varname(var->name()), _declarationId((forcedeclid == 0U) ? var->declarationId() : forcedeclid) : _varname(var->name()), _declarationId((forcedeclid == 0U) ? var->declarationId() : forcedeclid)
{ {
for (std::size_t i = 0; i < var->dimensions().size(); i++) for (std::size_t i = 0; i < var->dimensions().size(); i++)
_num.push_back(var->dimension(i)); _num.push_back(var->dimension(i));
if (var->typeEndToken()->str() == "*") if (var->typeEndToken()->str() == "*")
_element_size = symDb->sizeOfType(var->typeEndToken()); _element_size = symbolDatabase->sizeOfType(var->typeEndToken());
else if (var->typeStartToken()->strAt(-1) == "struct") else if (var->typeStartToken()->strAt(-1) == "struct")
_element_size = 100; _element_size = 100;
else { else {
_element_size = symDb->sizeOfType(var->typeEndToken()); _element_size = symbolDatabase->sizeOfType(var->typeEndToken());
} }
} }

View File

@ -180,7 +180,7 @@ public:
/** Check for buffer overruns (based on ArrayInfo) */ /** Check for buffer overruns (based on ArrayInfo) */
void checkScope(const Token *tok, const ArrayInfo &arrayInfo); void checkScope(const Token *tok, const ArrayInfo &arrayInfo);
void checkScope(const Token *tok, std::map<unsigned int, ArrayInfo> arrayInfo); void checkScope(const Token *tok, std::map<unsigned int, ArrayInfo> arrayInfos);
void checkScope_inner(const Token *tok, const ArrayInfo &arrayInfo); void checkScope_inner(const Token *tok, const ArrayInfo &arrayInfo);
/** Check for buffer overruns */ /** Check for buffer overruns */
@ -188,12 +188,12 @@ public:
/** /**
* Helper function for checkFunctionCall - check a function parameter * Helper function for checkFunctionCall - check a function parameter
* \param tok token for the function name * \param ftok token for the function name
* \param paramIndex on what parameter is the array used * \param paramIndex on what parameter is the array used
* \param arrayInfo the array information * \param arrayInfo the array information
* \param callstack call stack. This is used to prevent recursion and to provide better error messages. Pass a empty list from checkScope etc. * \param callstack call stack. This is used to prevent recursion and to provide better error messages. Pass a empty list from checkScope etc.
*/ */
void checkFunctionParameter(const Token &tok, const unsigned int paramIndex, const ArrayInfo &arrayInfo, const std::list<const Token *>& callstack); void checkFunctionParameter(const Token &ftok, const unsigned int paramIndex, const ArrayInfo &arrayInfo, const std::list<const Token *>& callstack);
/** /**
* Helper function that checks if the array is used and if so calls the checkFunctionCall * Helper function that checks if the array is used and if so calls the checkFunctionCall

View File

@ -1382,7 +1382,7 @@ void CheckIO::checkFormatString(const Token * const tok,
// We currently only support string literals, variables, and functions. // We currently only support string literals, variables, and functions.
/// @todo add non-string literals, and generic expressions /// @todo add non-string literals, and generic expressions
CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings, bool _isCPP) CheckIO::ArgumentInfo::ArgumentInfo(const Token * arg, const Settings *settings, bool _isCPP)
: variableInfo(nullptr) : variableInfo(nullptr)
, typeToken(nullptr) , typeToken(nullptr)
, functionInfo(nullptr) , functionInfo(nullptr)
@ -1392,14 +1392,14 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings,
, address(false) , address(false)
, isCPP(_isCPP) , isCPP(_isCPP)
{ {
if (!tok) if (!arg)
return; return;
// Use AST type info // Use AST type info
// TODO: This is a bailout so that old code is used in simple cases. Remove the old code and always use the AST type. // TODO: This is a bailout so that old code is used in simple cases. Remove the old code and always use the AST type.
if (!Token::Match(tok, "%str% ,|)") && !(Token::Match(tok,"%var%") && tok->variable() && tok->variable()->isArray())) { if (!Token::Match(arg, "%str% ,|)") && !(Token::Match(arg,"%var%") && arg->variable() && arg->variable()->isArray())) {
const Token *top = tok; const Token *top = arg;
while (top->astParent() && top->astParent()->str() != "," && top->astParent() != tok->previous()) while (top->astParent() && top->astParent()->str() != "," && top->astParent() != arg->previous())
top = top->astParent(); top = top->astParent();
const ValueType *valuetype = top->argumentType(); const ValueType *valuetype = top->argumentType();
if (valuetype && valuetype->type >= ValueType::Type::BOOL) { if (valuetype && valuetype->type >= ValueType::Type::BOOL) {
@ -1446,30 +1446,30 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings,
} }
if (tok->tokType() == Token::eString) { if (arg->tokType() == Token::eString) {
typeToken = tok; typeToken = arg;
return; return;
} else if (tok->str() == "&" || tok->tokType() == Token::eVariable || } else if (arg->str() == "&" || arg->tokType() == Token::eVariable ||
tok->tokType() == Token::eFunction || Token::Match(tok, "%type% ::") || arg->tokType() == Token::eFunction || Token::Match(arg, "%type% ::") ||
(Token::Match(tok, "static_cast|reinterpret_cast|const_cast <") && (Token::Match(arg, "static_cast|reinterpret_cast|const_cast <") &&
Token::simpleMatch(tok->linkAt(1), "> (") && Token::simpleMatch(arg->linkAt(1), "> (") &&
Token::Match(tok->linkAt(1)->linkAt(1), ") ,|)"))) { Token::Match(arg->linkAt(1)->linkAt(1), ") ,|)"))) {
if (Token::Match(tok, "static_cast|reinterpret_cast|const_cast")) { if (Token::Match(arg, "static_cast|reinterpret_cast|const_cast")) {
typeToken = tok->tokAt(2); typeToken = arg->tokAt(2);
while (typeToken->str() == "const" || typeToken->str() == "extern") while (typeToken->str() == "const" || typeToken->str() == "extern")
typeToken = typeToken->next(); typeToken = typeToken->next();
return; return;
} }
if (tok->str() == "&") { if (arg->str() == "&") {
address = true; address = true;
tok = tok->next(); arg = arg->next();
} }
while (Token::Match(tok, "%type% ::")) while (Token::Match(arg, "%type% ::"))
tok = tok->tokAt(2); arg = arg->tokAt(2);
if (!tok || !(tok->tokType() == Token::eVariable || tok->tokType() == Token::eFunction)) if (!arg || !(arg->tokType() == Token::eVariable || arg->tokType() == Token::eFunction))
return; return;
const Token *varTok = nullptr; const Token *varTok = nullptr;
const Token *tok1 = tok->next(); const Token *tok1 = arg->next();
for (; tok1; tok1 = tok1->next()) { for (; tok1; tok1 = tok1->next()) {
if (tok1->str() == "," || tok1->str() == ")") { if (tok1->str() == "," || tok1->str() == ")") {
if (tok1->previous()->str() == "]") { if (tok1->previous()->str() == "]") {

View File

@ -183,7 +183,7 @@ private:
void uselessCallsEmptyError(const Token *tok); void uselessCallsEmptyError(const Token *tok);
void uselessCallsRemoveError(const Token *tok, const std::string& function); void uselessCallsRemoveError(const Token *tok, const std::string& function);
void dereferenceInvalidIteratorError(const Token* deref, const std::string &itername); void dereferenceInvalidIteratorError(const Token* deref, const std::string &iterName);
void readingEmptyStlContainerError(const Token *tok); void readingEmptyStlContainerError(const Token *tok);

View File

@ -61,8 +61,8 @@ public:
bool checkIfForWhileHead(const Token *startparentheses, const Variable& var, bool suppressErrors, bool isuninit, Alloc alloc, const std::string &membervar); bool checkIfForWhileHead(const Token *startparentheses, const Variable& var, bool suppressErrors, bool isuninit, Alloc alloc, const std::string &membervar);
bool checkLoopBody(const Token *tok, const Variable& var, const Alloc alloc, const std::string &membervar, const bool suppressErrors); bool checkLoopBody(const Token *tok, const Variable& var, const Alloc alloc, const std::string &membervar, const bool suppressErrors);
void checkRhs(const Token *tok, const Variable &var, Alloc alloc, unsigned int number_of_if, const std::string &membervar); void checkRhs(const Token *tok, const Variable &var, Alloc alloc, unsigned int number_of_if, const std::string &membervar);
bool isVariableUsage(const Token *vartok, bool ispointer, Alloc alloc) const; bool isVariableUsage(const Token *vartok, bool pointer, Alloc alloc) const;
int isFunctionParUsage(const Token *vartok, bool ispointer, Alloc alloc) const; int isFunctionParUsage(const Token *vartok, bool pointer, Alloc alloc) const;
bool isMemberVariableAssignment(const Token *tok, const std::string &membervar) const; bool isMemberVariableAssignment(const Token *tok, const std::string &membervar) const;
bool isMemberVariableUsage(const Token *tok, bool isPointer, Alloc alloc, const std::string &membervar) const; bool isMemberVariableUsage(const Token *tok, bool isPointer, Alloc alloc, const std::string &membervar) const;

View File

@ -221,9 +221,9 @@ public:
/** /**
* Format the error message in XML format * Format the error message in XML format
* @param verbose use verbose message * @param verbose use verbose message
* @param ver XML version * @param version XML version
*/ */
std::string toXML(bool verbose, int ver) const; std::string toXML(bool verbose, int version) const;
static std::string getXMLHeader(int xml_version); static std::string getXMLHeader(int xml_version);
static std::string getXMLFooter(int xml_version); static std::string getXMLFooter(int xml_version);

View File

@ -569,19 +569,19 @@ template<> std::string MathLib::toString(double value)
return result.str(); return result.str();
} }
bool MathLib::isFloat(const std::string &s) bool MathLib::isFloat(const std::string &str)
{ {
return isDecimalFloat(s) || isFloatHex(s); return isDecimalFloat(str) || isFloatHex(str);
} }
bool MathLib::isDecimalFloat(const std::string &s) bool MathLib::isDecimalFloat(const std::string &str)
{ {
if (s.empty()) if (str.empty())
return false; return false;
enum State { enum State {
START, BASE_PLUSMINUS, BASE_DIGITS1, LEADING_DECIMAL, TRAILING_DECIMAL, BASE_DIGITS2, E, MANTISSA_PLUSMINUS, MANTISSA_DIGITS, SUFFIX_F, SUFFIX_L START, BASE_PLUSMINUS, BASE_DIGITS1, LEADING_DECIMAL, TRAILING_DECIMAL, BASE_DIGITS2, E, MANTISSA_PLUSMINUS, MANTISSA_DIGITS, SUFFIX_F, SUFFIX_L
} state = START; } state = START;
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) { for (std::string::const_iterator it = str.begin(); it != str.end(); ++it) {
switch (state) { switch (state) {
case START: case START:
if (*it=='+' || *it=='-') if (*it=='+' || *it=='-')
@ -672,18 +672,18 @@ bool MathLib::isDecimalFloat(const std::string &s)
return (state==BASE_DIGITS2 || state==MANTISSA_DIGITS || state==TRAILING_DECIMAL || state==SUFFIX_F || state==SUFFIX_L); return (state==BASE_DIGITS2 || state==MANTISSA_DIGITS || state==TRAILING_DECIMAL || state==SUFFIX_F || state==SUFFIX_L);
} }
bool MathLib::isNegative(const std::string &s) bool MathLib::isNegative(const std::string &str)
{ {
if (s.empty()) if (str.empty())
return false; return false;
return (s[0] == '-'); return (str[0] == '-');
} }
bool MathLib::isPositive(const std::string &s) bool MathLib::isPositive(const std::string &str)
{ {
if (s.empty()) if (str.empty())
return false; return false;
return !MathLib::isNegative(s); return !MathLib::isNegative(str);
} }
/*! \brief Does the string represent an octal number? /*! \brief Does the string represent an octal number?
@ -692,15 +692,15 @@ bool MathLib::isPositive(const std::string &s)
* Additional information can be found here: * Additional information can be found here:
* http://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html * http://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html
* *
* \param[in] s The string to check. In case the string is empty, the function returns false. * \param str The string to check. In case the string is empty, the function returns false.
* \return Return true in case a octal number is provided and false otherwise. * \return Return true in case a octal number is provided and false otherwise.
**/ **/
bool MathLib::isOct(const std::string& s) bool MathLib::isOct(const std::string& str)
{ {
enum Status { enum Status {
START, PLUSMINUS, OCTAL_PREFIX, DIGITS START, PLUSMINUS, OCTAL_PREFIX, DIGITS
} state = START; } state = START;
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) { for (std::string::const_iterator it = str.begin(); it != str.end(); ++it) {
switch (state) { switch (state) {
case START: case START:
if (*it == '+' || *it == '-') if (*it == '+' || *it == '-')
@ -726,19 +726,19 @@ bool MathLib::isOct(const std::string& s)
if (isOctalDigit(static_cast<unsigned char>(*it))) if (isOctalDigit(static_cast<unsigned char>(*it)))
state = DIGITS; state = DIGITS;
else else
return isValidIntegerSuffix(it,s.end()); return isValidIntegerSuffix(it,str.end());
break; break;
} }
} }
return state == DIGITS; return state == DIGITS;
} }
bool MathLib::isIntHex(const std::string& s) bool MathLib::isIntHex(const std::string& str)
{ {
enum Status { enum Status {
START, PLUSMINUS, HEX_PREFIX, DIGIT, DIGITS START, PLUSMINUS, HEX_PREFIX, DIGIT, DIGITS
} state = START; } state = START;
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) { for (std::string::const_iterator it = str.begin(); it != str.end(); ++it) {
switch (state) { switch (state) {
case START: case START:
if (*it == '+' || *it == '-') if (*it == '+' || *it == '-')
@ -770,19 +770,19 @@ bool MathLib::isIntHex(const std::string& s)
if (isxdigit(static_cast<unsigned char>(*it))) if (isxdigit(static_cast<unsigned char>(*it)))
state = DIGITS; state = DIGITS;
else else
return isValidIntegerSuffix(it,s.end()); return isValidIntegerSuffix(it,str.end());
break; break;
} }
} }
return state == DIGITS; return state == DIGITS;
} }
bool MathLib::isFloatHex(const std::string& s) bool MathLib::isFloatHex(const std::string& str)
{ {
enum Status { enum Status {
START, PLUSMINUS, HEX_PREFIX, WHOLE_NUMBER_DIGIT, WHOLE_NUMBER_DIGITS, FRACTION, EXPONENT_DIGIT, EXPONENT_DIGITS START, PLUSMINUS, HEX_PREFIX, WHOLE_NUMBER_DIGIT, WHOLE_NUMBER_DIGITS, FRACTION, EXPONENT_DIGIT, EXPONENT_DIGITS
} state = START; } state = START;
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) { for (std::string::const_iterator it = str.begin(); it != str.end(); ++it) {
switch (state) { switch (state) {
case START: case START:
if (*it == '+' || *it == '-') if (*it == '+' || *it == '-')
@ -935,15 +935,15 @@ bool MathLib::isValidIntegerSuffix(std::string::const_iterator it, std::string::
* Additional information can be found here: * Additional information can be found here:
* http://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html * http://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html
* *
* \param[in] s The string to check. In case the string is empty, the function returns false. * \param str The string to check. In case the string is empty, the function returns false.
* \return Return true in case a binary number is provided and false otherwise. * \return Return true in case a binary number is provided and false otherwise.
**/ **/
bool MathLib::isBin(const std::string& s) bool MathLib::isBin(const std::string& str)
{ {
enum Status { enum Status {
START, PLUSMINUS, GNU_BIN_PREFIX, DIGIT, DIGITS START, PLUSMINUS, GNU_BIN_PREFIX, DIGIT, DIGITS
} state = START; } state = START;
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) { for (std::string::const_iterator it = str.begin(); it != str.end(); ++it) {
switch (state) { switch (state) {
case START: case START:
if (*it == '+' || *it == '-') if (*it == '+' || *it == '-')
@ -975,19 +975,19 @@ bool MathLib::isBin(const std::string& s)
if (*it == '0' || *it == '1') if (*it == '0' || *it == '1')
state = DIGITS; state = DIGITS;
else else
return isValidIntegerSuffix(it,s.end()); return isValidIntegerSuffix(it,str.end());
break; break;
} }
} }
return state == DIGITS; return state == DIGITS;
} }
bool MathLib::isDec(const std::string & s) bool MathLib::isDec(const std::string & str)
{ {
enum Status { enum Status {
START, PLUSMINUS, DIGIT START, PLUSMINUS, DIGIT
} state = START; } state = START;
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) { for (std::string::const_iterator it = str.begin(); it != str.end(); ++it) {
switch (state) { switch (state) {
case START: case START:
if (*it == '+' || *it == '-') if (*it == '+' || *it == '-')
@ -1007,16 +1007,16 @@ bool MathLib::isDec(const std::string & s)
if (isdigit(static_cast<unsigned char>(*it))) if (isdigit(static_cast<unsigned char>(*it)))
state = DIGIT; state = DIGIT;
else else
return isValidIntegerSuffix(it,s.end()); return isValidIntegerSuffix(it,str.end());
break; break;
} }
} }
return state == DIGIT; return state == DIGIT;
} }
bool MathLib::isInt(const std::string & s) bool MathLib::isInt(const std::string & str)
{ {
return isDec(s) || isIntHex(s) || isOct(s) || isBin(s); return isDec(str) || isIntHex(str) || isOct(str) || isBin(str);
} }
static std::string getsuffix(const std::string& value) static std::string getsuffix(const std::string& value)

View File

@ -83,7 +83,7 @@ public:
void deallocateTokens(); void deallocateTokens();
/** append file name if seen the first time; return its index in any case */ /** append file name if seen the first time; return its index in any case */
unsigned int appendFileIfNew(const std::string &file); unsigned int appendFileIfNew(const std::string &fileName);
/** get first token of list */ /** get first token of list */
const Token *front() const { const Token *front() const {