Fixed #1684 (false positive: buffer access out of bounds when using extern variable declaration)

This commit is contained in:
Daniel Marjamäki 2010-05-16 20:21:22 +02:00
parent 4c6858fa9c
commit 56d176e1ce
2 changed files with 17 additions and 3 deletions

View File

@ -4381,12 +4381,18 @@ void Tokenizer::simplifyVarDecl()
} }
} }
else if (Token::Match(tok2, "%type% %var% [ %num% ] ,|=") || else if (Token::Match(tok2, "%type% %var% [ %num% ] ,|=|[") ||
Token::Match(tok2, "%type% %var% [ %var% ] ,|=")) Token::Match(tok2, "%type% %var% [ %var% ] ,|=|["))
{ {
tok2 = tok2->tokAt(5); // The ',' token tok2 = tok2->tokAt(5); // The ',' token
while (Token::Match(tok2, "[ %num% ]") || Token::Match(tok2, "[ %var% ]"))
tok2 = tok2->tokAt(3);
if (!Token::Match(tok2, "=|,"))
{
tok2 = NULL;
}
if (tok2->str() == "=") if (tok2 && tok2->str() == "=")
{ {
while (tok2 && tok2->str() != ",") while (tok2 && tok2->str() != ",")
{ {

View File

@ -177,6 +177,7 @@ private:
TEST_CASE(vardecl8); TEST_CASE(vardecl8);
TEST_CASE(vardecl9); TEST_CASE(vardecl9);
TEST_CASE(vardecl10); TEST_CASE(vardecl10);
TEST_CASE(vardecl11);
TEST_CASE(vardecl_stl); TEST_CASE(vardecl_stl);
TEST_CASE(vardecl_template); TEST_CASE(vardecl_template);
TEST_CASE(volatile_variables); TEST_CASE(volatile_variables);
@ -2794,6 +2795,13 @@ private:
ASSERT_EQUALS(code, tokenizeAndStringify(code)); ASSERT_EQUALS(code, tokenizeAndStringify(code));
} }
void vardecl11()
{
// ticket #1684
const char code[] = "char a[5][8], b[5][8];";
ASSERT_EQUALS("char a [ 5 ] [ 8 ] ; char b [ 5 ] [ 8 ] ;", tokenizeAndStringify(code));
}
void volatile_variables() void volatile_variables()
{ {
const char code[] = "volatile int a=0;\n" const char code[] = "volatile int a=0;\n"