Fixed #4880 (false negative: uninitialized variable, handling of conditional noreturn scopes)

This commit is contained in:
Daniel Marjamäki 2015-03-14 17:59:11 +01:00
parent 53e2d425d1
commit 42c4aa1c49
2 changed files with 11 additions and 1 deletions

View File

@ -1226,7 +1226,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
if (_tokenizer->IsScopeNoReturn(tok)) {
if (noreturn)
*noreturn = true;
return true;
return false;
}
break;

View File

@ -2112,6 +2112,16 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVarB("int foo(int a) {\n" // #4880
" int x;\n"
" if (a==1)\n"
" g(1);\n" // might be a noreturn function
" if (a==17)\n"
" g(2);\n" // might be a noreturn function
" return x;\n"
"}");
ASSERT_EQUALS("[test.cpp:7]: (error) Uninitialized variable: x\n", errout.str());
checkUninitVarB("void (*init)(char *str);\n"
"\n"
"char x() {\n"