Uninitialized variables: Fixed simple undetected case for '= %var% |' and '| %var% ;'

This commit is contained in:
Daniel Marjamäki 2010-11-16 20:16:44 +01:00
parent eb54be2b2a
commit aa653fe42b
2 changed files with 18 additions and 1 deletions

View File

@ -465,7 +465,7 @@ private:
}
// Used..
if (Token::Match(tok.previous(), "[[(,+-*/=] %var% []),;+-*/]"))
if (Token::Match(tok.previous(), "[[(,+-*/|=] %var% []),;+-*/|]"))
{
use(checks, &tok);
return &tok;

View File

@ -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()
{