Fixed #3980 (Variable not assigned a value)
This commit is contained in:
parent
bb068d2f78
commit
7975ffba21
|
@ -836,7 +836,14 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
|||
}
|
||||
|
||||
// assignment
|
||||
else if (Token::Match(tok, "%var% [") && Token::simpleMatch(skipBracketsAndMembers(tok->next()), "=")) {
|
||||
else if ((Token::Match(tok, "%var% [") && Token::simpleMatch(skipBracketsAndMembers(tok->next()), "=")) ||
|
||||
(Token::simpleMatch(tok, "* (") && Token::simpleMatch(tok->next()->link(), ") ="))) {
|
||||
if (tok->str() == "*") {
|
||||
tok = tok->tokAt(2);
|
||||
if (tok->str() == "(")
|
||||
tok = tok->link()->next();
|
||||
}
|
||||
|
||||
unsigned int varid = tok->varId();
|
||||
const Variables::VariableUsage *var = variables.find(varid);
|
||||
|
||||
|
|
|
@ -109,6 +109,7 @@ private:
|
|||
TEST_CASE(localvardynamic3); // ticket #3467
|
||||
TEST_CASE(localvararray1); // ticket #2780
|
||||
TEST_CASE(localvararray2); // ticket #3438
|
||||
TEST_CASE(localvararray3); // ticket #3980
|
||||
TEST_CASE(localvarstring1);
|
||||
TEST_CASE(localvarstring2); // ticket #2929
|
||||
TEST_CASE(localvarconst1);
|
||||
|
@ -3090,6 +3091,15 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvararray3() {
|
||||
functionVariableUsage("int foo() {\n"
|
||||
" int p[5][5];\n"
|
||||
" *((int*)p[0]) = 0;\n"
|
||||
" return p[0][0];\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvarstring1() { // ticket #1597
|
||||
functionVariableUsage("void foo() {\n"
|
||||
" std::string s;\n"
|
||||
|
|
Loading…
Reference in New Issue