Refactorizations:

- Added support for pointers in self assignement check
- Removed redundant for loop in checknullpointer.cpp
- Fixed warning about signed/unsigned mismatch in cppcheck.cpp by making Settings::_maxConfig unsigned
This commit is contained in:
PKEuS 2012-05-11 10:38:19 -07:00
parent 0452b03f53
commit 06a77679d4
5 changed files with 11 additions and 8 deletions

View File

@ -212,11 +212,8 @@ void CheckNullPointer::parseFunctionCall(const Token &tok, std::list<const Token
argListTok = formatStringTok->nextArgument(); // Find third parameter (first argument of va_args)
formatString = formatStringTok->strValue();
}
} else if (Token::Match(&tok, "snprintf|fnprintf")) {
const Token* formatStringTok = secondParam;
for (int i = 0; i < 1 && formatStringTok; i++) {
formatStringTok = formatStringTok->nextArgument(); // Find third parameter (format string)
}
} else if (Token::Match(&tok, "snprintf|fnprintf") && secondParam) {
const Token* formatStringTok = secondParam->nextArgument(); // Find third parameter (format string)
if (formatStringTok && formatStringTok->type() == Token::eString) {
argListTok = formatStringTok->nextArgument(); // Find fourth parameter (first argument of va_args)
formatString = formatStringTok->strValue();

View File

@ -894,7 +894,7 @@ void CheckOther::coutCerrMisusageError(const Token* tok, const std::string& stre
static bool isPOD(const Variable* var)
{
// TODO: Implement real support for POD definition
return(var && var->nameToken()->previous()->isStandardType());
return(var && (var->isPointer() || var->nameToken()->previous()->isStandardType()));
}
void CheckOther::checkSelfAssignment()

View File

@ -192,7 +192,7 @@ unsigned int CppCheck::processFile(const std::string& filename)
reportErr(errmsg);
}
int checkCount = 0;
unsigned int checkCount = 0;
for (std::list<std::string>::const_iterator it = configurations.begin(); it != configurations.end(); ++it) {
// Check only a few configurations (default 12), after that bail out, unless --force
// was used.

View File

@ -130,7 +130,7 @@ public:
/** @brief Maximum number of configurations to check before bailing.
Default is 12. (--max-configs=N) */
int _maxConfigs;
unsigned int _maxConfigs;
/**
* @brief Returns true if given id is in the list of

View File

@ -2102,6 +2102,12 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
check("void foo() {\n"
" BAR *x = getx();\n"
" x = x;\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (warning) Redundant assignment of \"x\" to itself\n", errout.str());
// non-primitive type -> there might be some side effects
check("void foo()\n"
"{\n"