Fixed #4487 (False positive: variable is not assigned a value (pointer alias))
This commit is contained in:
parent
54d398c7dd
commit
dd155b57e4
|
@ -605,6 +605,16 @@ static const Token* doAssignment(Variables &variables, const Token *tok, bool de
|
|||
}
|
||||
}
|
||||
|
||||
// Possible pointer alias
|
||||
else if (Token::Match(tok, "%var% = %var% ;")) {
|
||||
const unsigned int varid2 = tok->tokAt(2)->varId();
|
||||
Variables::VariableUsage *var2 = variables.find(varid2);
|
||||
if (var2 && (var2->_type == Variables::array ||
|
||||
var2->_type == Variables::pointer)) {
|
||||
variables.use(varid2,tok);
|
||||
}
|
||||
}
|
||||
|
||||
return tok;
|
||||
}
|
||||
|
||||
|
|
|
@ -104,6 +104,7 @@ private:
|
|||
TEST_CASE(localvaralias10); // ticket #2004
|
||||
TEST_CASE(localvaralias11); // ticket #4423 - iterator
|
||||
TEST_CASE(localvaralias12); // ticket #4394
|
||||
TEST_CASE(localvaralias13); // ticket #4487
|
||||
TEST_CASE(localvarasm);
|
||||
TEST_CASE(localvarstatic);
|
||||
TEST_CASE(localvarextern);
|
||||
|
@ -2744,6 +2745,22 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvaralias13() { // #4487
|
||||
functionVariableUsage("void f(char *p) {\n"
|
||||
" char a[4];\n"
|
||||
" p = a;\n"
|
||||
" strcpy(p, \"x\");\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
functionVariableUsage("void f(char *p) {\n"
|
||||
" char a[4];\n"
|
||||
" p = a;\n"
|
||||
" strcpy(p, \"x\");\n"
|
||||
"}");
|
||||
TODO_ASSERT_EQUALS("a is assigned value that is never used", "", errout.str());
|
||||
}
|
||||
|
||||
void localvarasm() {
|
||||
functionVariableUsage("void foo(int &b)\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue