This commit is contained in:
Sébastien Debrard 2011-02-17 19:45:50 +01:00
commit cabd3e30a9
9 changed files with 59 additions and 8 deletions

View File

@ -96,7 +96,7 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
std::vector<std::string>::iterator iterBegin = filenames.begin();
for (int i = (int)filenames.size() - 1; i >= 0; i--)
{
if (matcher.Match(filenames[i]))
if (matcher.Match(filenames[(unsigned int)i]))
filenames.erase(iterBegin + i);
}
}

View File

@ -197,7 +197,7 @@ unsigned int CppCheck::check()
_errorLogger.reportOut("Bailing out from checking " + fixedpath + ": " + e.what());
}
reportUnmatchedSuppressions(_settings.nomsg.getUnmatchedLocalSuppressions());
reportUnmatchedSuppressions(_settings.nomsg.getUnmatchedLocalSuppressions(fname));
_errorLogger.reportStatus(c + 1, (unsigned int)_filenames.size());
}
@ -348,7 +348,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[])
unsigned int pos2 = (unsigned int)ovector[1];
// jump to the end of the match for the next pcre_exec
pos = pos2;
pos = (int)pos2;
// determine location..
ErrorLogger::ErrorMessage::FileLocation loc;

View File

@ -110,7 +110,7 @@ public:
line = 0;
}
FileLocation(const std::string &file, int aline)
FileLocation(const std::string &file, unsigned int aline)
: line(aline), _file(file)
{
}

View File

@ -312,12 +312,13 @@ bool Settings::Suppressions::isSuppressedLocal(const std::string &errorId, const
return _suppressions[errorId].isSuppressedLocal(file, line);
}
std::list<Settings::Suppressions::SuppressionEntry> Settings::Suppressions::getUnmatchedLocalSuppressions() const
std::list<Settings::Suppressions::SuppressionEntry> Settings::Suppressions::getUnmatchedLocalSuppressions(const std::string &file) const
{
std::list<SuppressionEntry> r;
for (std::map<std::string, FileMatcher>::const_iterator i = _suppressions.begin(); i != _suppressions.end(); ++i)
{
for (std::map<std::string, std::map<unsigned int, bool> >::const_iterator f = i->second._files.begin(); f != i->second._files.end(); ++f)
std::map<std::string, std::map<unsigned int, bool> >::const_iterator f = i->second._files.find(file);
if (f != i->second._files.end())
{
for (std::map<unsigned int, bool>::const_iterator l = f->second.begin(); l != f->second.end(); ++l)
{

View File

@ -239,7 +239,7 @@ public:
* @brief Returns list of unmatched local (per-file) suppressions.
* @return list of unmatched suppressions
*/
std::list<SuppressionEntry> getUnmatchedLocalSuppressions() const;
std::list<SuppressionEntry> getUnmatchedLocalSuppressions(const std::string &file) const;
/**
* @brief Returns list of unmatched global (glob pattern) suppressions.

View File

@ -4712,7 +4712,7 @@ void Tokenizer::simplifyCompoundAssignment()
// "a+=b" => "a = a + b"
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (Token::Match(tok, "[;{}:] *| (| %var%"))
if (Token::Match(tok, "[;{}] (") || Token::Match(tok, "[;{}:] *| (| %var%"))
{
if (tok->str() == ":")
{

View File

@ -2932,6 +2932,17 @@ private:
" memset(&fail, 0, sizeof(struct A));\n"
"}\n");
ASSERT_EQUALS("[test.cpp:10]: (error) Using 'memset' on struct that contains a 'std::string'\n", errout.str());
checkNoMemset("struct Fred\n"
"{\n"
" std::string s;\n"
"};\n"
"void f()\n"
"{\n"
" Fred fred;\n"
" memset(&fred, 0, sizeof(fred));\n"
"}\n");
TODO_ASSERT_EQUALS("error", "", errout.str());
}
void memsetVector()

View File

@ -36,6 +36,7 @@ private:
void run()
{
TEST_CASE(suppressionsSettings);
TEST_CASE(suppressionsMultiFile);
}
// Check the suppression
@ -84,6 +85,26 @@ private:
reportUnmatchedSuppressions(settings.nomsg.getUnmatchedGlobalSuppressions());
}
// Check the suppression for multiple files
void checkSuppression(const char *names[], const char *codes[], const std::string &suppression = "")
{
// Clear the error log
errout.str("");
Settings settings;
settings._inlineSuppressions = true;
if (!suppression.empty())
settings.nomsg.addSuppressionLine(suppression);
CppCheck cppCheck(*this, true);
cppCheck.settings(settings);
for (int i = 0; names[i] != NULL; ++i)
cppCheck.addFile(names[i], codes[i]);
cppCheck.check();
reportUnmatchedSuppressions(cppCheck.settings().nomsg.getUnmatchedGlobalSuppressions());
}
void runChecks(void (TestSuppressions::*check)(const char[], const std::string &))
{
// check to make sure the appropriate error is present
@ -167,6 +188,23 @@ private:
runChecks(&TestSuppressions::checkSuppressionThreads);
}
void suppressionsMultiFile()
{
const char *names[] = {"abc.cpp", "xyz.cpp", NULL};
const char *codes[] = {
"void f() {\n"
"}\n",
"void f() {\n"
" int a;\n"
" a++;\n"
"}\n",
};
// suppress uninitvar for this file and line
checkSuppression(names, codes, "uninitvar:xyz.cpp:3");
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestSuppressions)

View File

@ -5196,6 +5196,7 @@ private:
ASSERT_EQUALS("{ x = x >> y ; }", tokenizeAndStringify("{ x >>= y;}"));
ASSERT_EQUALS("; * p = * p + y ;", tokenizeAndStringify("; *p += y;"));
ASSERT_EQUALS("; ( * p ) = ( * p ) + y ;", tokenizeAndStringify("; (*p) += y;"));
ASSERT_EQUALS("; * ( p [ 0 ] ) = * ( p [ 0 ] ) + y ;", tokenizeAndStringify("; *(p[0]) += y;"));
ASSERT_EQUALS("case 0 : x = x + y ; break ;", tokenizeAndStringify("case 0: x += y; break;"));