Merge branch 'master' of git@github.com:danmar/cppcheck
This commit is contained in:
commit
ce595dd5c7
|
@ -945,9 +945,8 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::list<const Toke
|
||||||
}
|
}
|
||||||
|
|
||||||
// Callback..
|
// Callback..
|
||||||
bool matchFirst;
|
bool matchFirst = Token::Match(tok, "( %var%");
|
||||||
if ((matchFirst = Token::Match(tok, "( %var%")) ||
|
if (matchFirst || Token::Match(tok, "( * %var%"))
|
||||||
Token::Match(tok, "( * %var%"))
|
|
||||||
{
|
{
|
||||||
int tokIdx = matchFirst ? 2 : 3;
|
int tokIdx = matchFirst ? 2 : 3;
|
||||||
|
|
||||||
|
|
|
@ -45,14 +45,18 @@ void CheckOther::warningOldStylePointerCast()
|
||||||
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
|
||||||
{
|
{
|
||||||
// Old style pointer casting..
|
// Old style pointer casting..
|
||||||
if (!Token::Match(tok, "( %type% * ) %var%"))
|
if (!Token::Match(tok, "( const| %type% * ) %var%"))
|
||||||
continue;
|
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;
|
continue;
|
||||||
|
|
||||||
// Is "type" a class?
|
// 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()))
|
if (!Token::findmatch(_tokenizer->tokens(), pattern.c_str()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
|
||||||
std::string temp;
|
std::string temp;
|
||||||
for (unsigned int i = 0; i < len && iss.good(); ++i)
|
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);
|
temp.append(1, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ bool ErrorLogger::ErrorMessage::deserialize(const std::string &data)
|
||||||
std::string temp;
|
std::string temp;
|
||||||
for (unsigned int i = 0; i < len && iss.good(); ++i)
|
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);
|
temp.append(1, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -286,7 +286,7 @@ std::string Preprocessor::read(std::istream &istr)
|
||||||
if (ch == '\\')
|
if (ch == '\\')
|
||||||
{
|
{
|
||||||
char chNext = 0;
|
char chNext = 0;
|
||||||
while (true)
|
for (;;)
|
||||||
{
|
{
|
||||||
chNext = (char)istr.peek();
|
chNext = (char)istr.peek();
|
||||||
if (chNext != '\n' && chNext != '\r' && (chNext > 0) &&
|
if (chNext != '\n' && chNext != '\r' && (chNext > 0) &&
|
||||||
|
|
|
@ -527,6 +527,12 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:4]: (style) C-style pointer casting\n", errout.str());
|
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"
|
checkOldStylePointerCast("class B;\n"
|
||||||
"class A\n"
|
"class A\n"
|
||||||
|
@ -534,6 +540,13 @@ private:
|
||||||
" virtual void abc(B *) const = 0;\n"
|
" virtual void abc(B *) const = 0;\n"
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue