Fixed #2780 (false positive: variable p is not assigned a value 'int p[2]; *p = 0;')

This commit is contained in:
Daniel Marjamäki 2011-05-11 18:58:25 +02:00
parent 1c992fe25a
commit 144d811e54
2 changed files with 12 additions and 0 deletions

View File

@ -2069,6 +2069,9 @@ void CheckOther::functionVariableUsage()
if (dereference)
{
Variables::VariableUsage *var = variables.find(varid1);
if (var && var->_type == Variables::array)
variables.write(varid1);
variables.writeAliases(varid1);
variables.read(varid1);
}

View File

@ -96,6 +96,7 @@ private:
TEST_CASE(localvarasm);
TEST_CASE(localvarstatic);
TEST_CASE(localvardynamic);
TEST_CASE(localvararray1); // ticket #2780
// Don't give false positives for variables in structs/unions
TEST_CASE(localvarStruct1);
@ -2643,7 +2644,15 @@ private:
" delete[] ptr;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void localvararray1()
{
functionVariableUsage("void foo() {\n"
" int p[5];\n"
" *p = 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
};