Merge branch 'master' of git@github.com:danmar/cppcheck

This commit is contained in:
Daniel Marjamäki 2009-07-21 07:41:43 +02:00
commit ce595dd5c7
5 changed files with 25 additions and 9 deletions

View File

@ -945,9 +945,8 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
}
// Callback..
bool matchFirst;
if ((matchFirst = Token::Match(tok, "( %var%")) ||
Token::Match(tok, "( * %var%"))
bool matchFirst = Token::Match(tok, "( %var%");
if (matchFirst || Token::Match(tok, "( * %var%"))
{
int tokIdx = matchFirst ? 2 : 3;

View File

@ -45,14 +45,18 @@ void CheckOther::warningOldStylePointerCast()
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
{
// Old style pointer casting..
if (!Token::Match(tok, "( %type% * ) %var%"))
if (!Token::Match(tok, "( const| %type% * ) %var%"))
continue;
if (Token::simpleMatch(tok->tokAt(4), "const"))
int addToIndex = 0;
if (Token::simpleMatch(tok->tokAt(1), "const"))
addToIndex = 1;
if (Token::simpleMatch(tok->tokAt(4 + addToIndex), "const"))
continue;
// Is "type" a class?
const std::string pattern("class " + tok->next()->str());
const std::string pattern("class " + tok->tokAt(1 + addToIndex)->str());
if (!Token::findmatch(_tokenizer->tokens(), pattern.c_str()))
continue;

View File

@ -67,7 +67,7 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
std::string temp;
for (unsigned int i = 0; i < len && iss.good(); ++i)
{
char c = iss.get();
char c = static_cast<char>(iss.get());
temp.append(1, c);
}
@ -94,7 +94,7 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
std::string temp;
for (unsigned int i = 0; i < len && iss.good(); ++i)
{
char c = iss.get();
char c = static_cast<char>(iss.get());
temp.append(1, c);
}

View File

@ -286,7 +286,7 @@ std::string Preprocessor::read(std::istream &istr)
if (ch == '\\')
{
char chNext = 0;
while (true)
for (;;)
{
chNext = (char)istr.peek();
if (chNext != '\n' && chNext != '\r' && (chNext > 0) &&

View File

@ -527,6 +527,12 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout.str());
checkOldStylePointerCast("class Base;\n"
"void foo()\n"
"{\n"
" Base * b = (const Base *) derived;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout.str());
checkOldStylePointerCast("class B;\n"
"class A\n"
@ -534,6 +540,13 @@ private:
" virtual void abc(B *) const = 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
checkOldStylePointerCast("class B;\n"
"class A\n"
"{\n"
" virtual void abc(const B *) const = 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
};