uninitialized variables: fixed false positive when switch is used
This commit is contained in:
parent
765c824c6f
commit
2cf849a9b8
|
@ -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;
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue