uninitialized variables: fixed false positive when switch is used

This commit is contained in:
Daniel Marjamäki 2009-10-30 14:52:20 +01:00
parent 765c824c6f
commit 2cf849a9b8
2 changed files with 16 additions and 1 deletions

View File

@ -1177,7 +1177,7 @@ static const Token *uninitvar_checkscope(const Token *tok, const unsigned int va
return 0;
// todo: handle for/while
if (Token::Match(tok, "for|while"))
if (Token::Match(tok, "for|while|switch"))
{
init = true;
return 0;

View File

@ -979,6 +979,21 @@ private:
"}\n");
ASSERT_EQUALS("", errout.str());
// switch..
checkUninitVar("char * f()\n"
"{\n"
" static char ret[200];\n"
" memset(ret, 0, sizeof(ret));\n"
" switch (x)\n"
" {\n"
" case 1: return ret;\n"
" case 2: return ret;\n"
" }\n"
" return 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// member variables..
checkUninitVar("class Fred\n"
"{\n"