Fixed #2205 (False positive: variable is assigned a value that is never used (assigning to dereferenced casted pointers))
This commit is contained in:
parent
6d1c0687c9
commit
7b3e7f6467
|
@ -1543,7 +1543,8 @@ void CheckOther::functionVariableUsage()
|
|||
variables.readAll(tok->next()->varId());
|
||||
|
||||
// assignment
|
||||
else if (Token::Match(tok, "*| (| ++|--| %var% ++|--| )| ="))
|
||||
else if (Token::Match(tok, "*| (| ++|--| %var% ++|--| )| =") ||
|
||||
Token::Match(tok, "*| ( const| %type% *| ) %var% ="))
|
||||
{
|
||||
bool dereference = false;
|
||||
bool pre = false;
|
||||
|
@ -1555,7 +1556,10 @@ void CheckOther::functionVariableUsage()
|
|||
tok = tok->next();
|
||||
}
|
||||
|
||||
if (tok->str() == "(")
|
||||
if (Token::Match(tok, "( const| %type% *| ) %var% ="))
|
||||
tok = tok->link()->next();
|
||||
|
||||
else if (tok->str() == "(")
|
||||
tok = tok->next();
|
||||
|
||||
if (Token::Match(tok, "++|--"))
|
||||
|
|
|
@ -74,6 +74,7 @@ private:
|
|||
TEST_CASE(localvar25); // ticket #1729
|
||||
TEST_CASE(localvar26); // ticket #1894
|
||||
TEST_CASE(localvar27); // ticket #2160
|
||||
TEST_CASE(localvar28); // ticket #2205
|
||||
TEST_CASE(localvaralias1);
|
||||
TEST_CASE(localvaralias2); // ticket #1637
|
||||
TEST_CASE(localvaralias3); // ticket #1639
|
||||
|
@ -1282,6 +1283,16 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvar28() // ticket #2205
|
||||
{
|
||||
functionVariableUsage("void f(char* buffer, int value) {\n"
|
||||
" char* pos = buffer;\n"
|
||||
" int size = value;\n"
|
||||
" *(int*)pos = size;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvaralias1()
|
||||
{
|
||||
functionVariableUsage("void foo()\n"
|
||||
|
|
Loading…
Reference in New Issue