Uninitialized variables: Fixed simple undetected case for '= %var% |' and '| %var% ;'
This commit is contained in:
parent
eb54be2b2a
commit
aa653fe42b
|
@ -465,7 +465,7 @@ private:
|
|||
}
|
||||
|
||||
// Used..
|
||||
if (Token::Match(tok.previous(), "[[(,+-*/=] %var% []),;+-*/]"))
|
||||
if (Token::Match(tok.previous(), "[[(,+-*/|=] %var% []),;+-*/|]"))
|
||||
{
|
||||
use(checks, &tok);
|
||||
return &tok;
|
||||
|
|
|
@ -35,6 +35,7 @@ private:
|
|||
void run()
|
||||
{
|
||||
TEST_CASE(uninitvar1);
|
||||
TEST_CASE(uninitvar_bitop); // using uninitialized operand in bit operation
|
||||
TEST_CASE(uninitvar_alloc); // data is allocated but not initialized
|
||||
TEST_CASE(uninitvar_arrays); // arrays
|
||||
TEST_CASE(uninitvar_class); // class/struct
|
||||
|
@ -450,6 +451,22 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
void uninitvar_bitop()
|
||||
{
|
||||
checkUninitVar("void foo() {\n"
|
||||
" int b;\n"
|
||||
" c = a | b;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: b\n", errout.str());
|
||||
|
||||
checkUninitVar("void foo() {\n"
|
||||
" int b;\n"
|
||||
" c = b | a;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: b\n", errout.str());
|
||||
}
|
||||
|
||||
// if..
|
||||
void uninitvar_if()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue