Uninitialized variables: typeof doesn't dereference. Ticket: #2367

This commit is contained in:
Daniel Marjamäki 2010-12-30 21:30:46 +01:00
parent 307178d3c2
commit 8bdb05da6e
2 changed files with 28 additions and 1 deletions

View File

@ -33,6 +33,17 @@ CheckUninitVar instance;
//---------------------------------------------------------------------------
/** Is string uppercase? */
static bool isUpper(const std::string &str)
{
for (unsigned int i = 0; i < str.length(); ++i)
{
if (str[i] >= 'a' && str[i] <= 'z')
return false;
}
return true;
}
/// @addtogroup Checks
/// @{
@ -578,7 +589,9 @@ private:
if (Token::Match(&tok, "%var% (") && uvarFunctions.find(tok.str()) == uvarFunctions.end())
{
if (Token::Match(&tok, "sizeof|typeof ("))
// sizeof/typeof doesn't dereference. A function name that is all uppercase
// might be an unexpanded macro that uses sizeof/typeof
if (Token::Match(&tok, "sizeof|typeof (") || isUpper(tok.str()))
return tok.next()->link();
// deallocate pointer
@ -656,6 +669,14 @@ private:
break;
}
// ticket #2367 : unexpanded macro that uses sizeof|typeof?
else if (Token::Match(tok2, "%type% (") && isUpper(tok2->str()))
{
tok2 = tok2->next()->link();
if (!tok2)
break;
}
else if (tok2->varId())
{
if (Token::Match(tok2->tokAt(-2), "[(,] *") || Token::Match(tok2->next(), ". %var%"))

View File

@ -1406,6 +1406,12 @@ private:
" ab(typeof(s->status));\n"
"}\n");
ASSERT_EQUALS("", errout.str());
checkUninitVar("void f() {\n"
" struct SData * s;\n"
" TYPEOF(s->status);\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
};