Fixed #7121 (False positive 'Uninitialized variable' converting pointer to reference)
This commit is contained in:
parent
5cd36d6f8a
commit
459a4e0cbe
|
@ -796,6 +796,9 @@ bool CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc al
|
|||
}
|
||||
|
||||
if (Token::Match(vartok->previous(), "++|--|%cop%")) {
|
||||
if (_tokenizer->isCPP() && alloc == ARRAY && Token::Match(vartok->tokAt(-4), "& %var% =|( *"))
|
||||
return false;
|
||||
|
||||
if (_tokenizer->isCPP() && Token::Match(vartok->previous(), ">>|<<")) {
|
||||
const Token* tok2 = vartok->previous();
|
||||
if (Token::simpleMatch(tok2->astOperand1(), ">>"))
|
||||
|
|
|
@ -2743,6 +2743,12 @@ private:
|
|||
TODO_ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: x\n",
|
||||
"", errout.str());
|
||||
|
||||
checkUninitVar("void f() {\n"
|
||||
" int x[10];\n"
|
||||
" int &x0(*x);\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// ....
|
||||
checkUninitVar("struct ABC { int a; };\n" // struct initialization
|
||||
"void clear(struct ABC &abc);\n"
|
||||
|
@ -3581,12 +3587,6 @@ private:
|
|||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar("void f() {\n"
|
||||
" char *s = malloc(100);\n"
|
||||
" *s = x;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkUninitVar("void f() {\n"
|
||||
" char *p = malloc(100);\n"
|
||||
" p || assert_failed();\n"
|
||||
|
|
Loading…
Reference in New Issue