Fixed #1948 (C++ class scoping not followed)

This commit is contained in:
Daniel Marjamäki 2010-08-24 22:03:18 +02:00
parent ca407110dc
commit e7f7c77eab
2 changed files with 26 additions and 4 deletions

View File

@ -1221,10 +1221,16 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable()
void CheckBufferOverrun::checkStructVariable()
{
const char declstruct[] = "struct|class %var% {|:";
for (const Token *tok = Token::findmatch(_tokenizer->tokens(), declstruct);
tok; tok = Token::findmatch(tok->next(), declstruct))
for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next())
{
if (tok->str() == "{")
{
tok = tok->link();
}
if (!Token::Match(tok, "struct|class %var% {|:"))
continue;
const std::string &structname = tok->next()->str();
const Token *tok2 = tok;
@ -1295,7 +1301,6 @@ void CheckBufferOverrun::checkStructVariable()
else
continue;
// Goto end of statement.
const Token *CheckTok = NULL;
while (tok3)

View File

@ -175,6 +175,8 @@ private:
TEST_CASE(executionPaths2);
TEST_CASE(cmdLineArgs1);
TEST_CASE(scope); // handling different scopes
}
@ -2485,6 +2487,21 @@ private:
ASSERT_EQUALS("", errout.str());
}
void scope()
{
check("class A {\n"
"private:\n"
" struct X { char buf[10]; };\n"
"}\n"
"\n"
"void f()\n"
"{\n"
" X x;\n"
" x.buf[10] = 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestBufferOverrun)