Fixed ticket #3481 (segmentation fault of cppcheck)
This commit is contained in:
parent
a951d34aa8
commit
57fcde8090
|
@ -621,15 +621,15 @@ void CheckUnusedVar::checkFunctionVariableUsage_iterateScopes(const Scope* const
|
|||
if (i->isArray() && Token::Match(i->nameToken(), "%var% [ %var% ]")) // Array index variable read.
|
||||
variables.read(i->nameToken()->tokAt(2)->varId());
|
||||
|
||||
if (Token::simpleMatch(defValTok, "= {")) {
|
||||
for (const Token* tok = defValTok; tok && tok != defValTok->linkAt(1); tok = tok->next())
|
||||
if (Token::Match(tok, "%var%")) // Variables used to initialize the array read.
|
||||
variables.read(tok->varId());
|
||||
if (defValTok && defValTok->str() == "=") {
|
||||
if (defValTok->next() && defValTok->next()->str() == "{") {
|
||||
for (const Token* tok = defValTok; tok && tok != defValTok->linkAt(1); tok = tok->next())
|
||||
if (Token::Match(tok, "%var%")) // Variables used to initialize the array read.
|
||||
variables.read(tok->varId());
|
||||
} else
|
||||
doAssignment(variables, i->nameToken(), false, scope);
|
||||
} else if (Token::Match(defValTok, "( %var% )")) // Variables used to initialize the variable read.
|
||||
variables.readAll(defValTok->next()->varId()); // ReadAll?
|
||||
else if (defValTok->str() == "=") {
|
||||
doAssignment(variables, i->nameToken(), false, scope);
|
||||
}
|
||||
}
|
||||
|
||||
// Check variable usage
|
||||
|
|
|
@ -86,6 +86,7 @@ private:
|
|||
TEST_CASE(localvar38);
|
||||
TEST_CASE(localvar39); // ticket #3454
|
||||
TEST_CASE(localvar40); // ticket #3473
|
||||
TEST_CASE(localvar41); // ticket #3481
|
||||
TEST_CASE(localvaralias1);
|
||||
TEST_CASE(localvaralias2); // ticket #1637
|
||||
TEST_CASE(localvaralias3); // ticket #1639
|
||||
|
@ -1390,6 +1391,15 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvar41() {
|
||||
//garbage code : don't crash
|
||||
functionVariableUsage("{\n"
|
||||
" if (1) = x\n"
|
||||
" else abort s[2]\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvaralias1() {
|
||||
functionVariableUsage("void foo()\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue