Fixed #2087 (False positive: Array 'str[1]' index 1 out of bounds)

This commit is contained in:
Daniel Marjamäki 2010-10-12 21:52:02 +02:00
parent 9e15c4ef38
commit 2334192bff
2 changed files with 12 additions and 0 deletions

View File

@ -2095,6 +2095,12 @@ void Tokenizer::arraySize()
{
for (Token *tok = _tokens; tok; tok = tok->next())
{
if (Token::Match(tok, "%var% [ ] = { %str% }"))
{
tok->tokAt(4)->deleteThis();
tok->tokAt(5)->deleteThis();
}
if (Token::Match(tok, "%var% [ ] = {"))
{
unsigned int sz = 1;

View File

@ -934,6 +934,12 @@ private:
ASSERT_EQUALS("; const char str [ 1 ] = { '1' } ; 1 ;", sizeof_(code));
}
{
// Ticket #2087
const char code[] = "; const char str[] = {\"abc\"}; sizeof(str);";
ASSERT_EQUALS("; const char str [ 4 ] = \"abc\" ; 4 ;", sizeof_(code));
}
// ticket #716 - sizeof string
{
std::ostringstream expected;