Fixed #809 (Tokenizer: don't replace sizeof() of unknown type to zero)

http://sourceforge.net/apps/trac/cppcheck/ticket/809
This commit is contained in:
Slava Semushin 2009-10-10 19:26:03 +07:00
parent b67fe861b8
commit 237dcb9533
2 changed files with 18 additions and 1 deletions

View File

@ -1435,7 +1435,13 @@ void Tokenizer::simplifySizeof()
Token::Match(tok->tokAt(-2), "[;{}(,] %type% %var% [;),]") ||
Token::Match(tok->tokAt(-3), "[;{}(,] const %type% %var% [;),]"))
{
sizeOfVar[varId] = MathLib::toString<long>(sizeOfType(tok->tokAt(-1)));
const int size = sizeOfType(tok->previous());
if (size <= 0)
{
continue;
}
sizeOfVar[varId] = MathLib::toString<long>(size);
}
else if (Token::Match(tok->tokAt(-1), "%type% %var% [ %num% ] [;=]") ||

View File

@ -65,6 +65,7 @@ private:
TEST_CASE(sizeof7);
TEST_CASE(sizeof8);
TEST_CASE(sizeof9);
TEST_CASE(sizeof10);
TEST_CASE(casting);
TEST_CASE(template1);
@ -775,6 +776,16 @@ private:
}
}
void sizeof10()
{
// ticket #809
const char code[] = "int m ; "
"compat_ulong_t um ; "
"size_t size ; size = sizeof ( m ) / sizeof ( um ) ;";
ASSERT_EQUALS(code, tok(code));
}
void casting()
{
{