Fixed #2030 (False positive: Uninitialized variable when function does not return)
This commit is contained in:
parent
3a4cda0f0d
commit
5688412f00
|
@ -305,7 +305,9 @@ static void checkExecutionPaths_(const Token *tok, std::list<ExecutionPath *> &c
|
|||
}
|
||||
|
||||
// might be a noreturn function..
|
||||
if (Token::Match(tok->previous(), "[;{}] %var% ( ) ; }") && tok->varId() == 0)
|
||||
if (tok->varId() == 0 &&
|
||||
(Token::Match(tok->previous(), "[;{}] %var% ( ) ; }") ||
|
||||
Token::Match(tok->previous(), "[;{}] %var% ( %num% ) ; }")))
|
||||
{
|
||||
ExecutionPath::bailOut(checks);
|
||||
return;
|
||||
|
|
|
@ -2353,6 +2353,27 @@ private:
|
|||
" f();\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: f\n", errout.str());
|
||||
|
||||
// calling noreturn function..
|
||||
checkUninitVar("int foo(int a) {\n"
|
||||
" int x;\n"
|
||||
" if (a==1)\n"
|
||||
" g();\n" // might be a noreturn function
|
||||
" else\n"
|
||||
" x = 3;\n"
|
||||
" return x;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar("int foo(int a) {\n"
|
||||
" int x;\n"
|
||||
" if (a==1)\n"
|
||||
" g(1);\n" // might be a noreturn function
|
||||
" else\n"
|
||||
" x = 3;\n"
|
||||
" return x;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue