fix #2765 (Non local address detected as address of local auto-variable)

This commit is contained in:
Robert Reif 2011-05-06 19:26:04 -04:00
parent ccb831d375
commit bb5dfa58a1
2 changed files with 14 additions and 4 deletions

View File

@ -53,7 +53,7 @@ bool CheckAutoVariables::isAutoVar(unsigned int varId)
{
const Variable *var = _tokenizer->getSymbolDatabase()->getVariableFromVarId(varId);
if (!var || !var->isLocal() || var->isStatic() || var->isArray())
if (!var || !var->isLocal() || var->isStatic() || var->isArray() || var->typeEndToken()->str() == "*")
return false;
return true;
@ -98,7 +98,7 @@ void CheckAutoVariables::autoVariables()
if (Token::Match(tok, "[;{}] * %var% = & %var%") && errorAv(tok->tokAt(2), tok->tokAt(5)))
{
const Variable * var = symbolDatabase->getVariableFromVarId(tok->tokAt(5)->varId());
if (var && (!var->isClass() || var->type()))
if (var && (!var->isClass() || var->type()))
errorAutoVariableAssignment(tok);
}
else if (Token::Match(tok, "[;{}] %var% [ %any% ] = & %var%") && errorAv(tok->tokAt(1), tok->tokAt(7)))

View File

@ -75,7 +75,8 @@ private:
TEST_CASE(testautovar_return2);
TEST_CASE(testautovar_extern);
TEST_CASE(testinvaliddealloc);
TEST_CASE(testassign); // Ticket #1819
TEST_CASE(testassign1); // Ticket #1819
TEST_CASE(testassign2); // Ticket #2765
TEST_CASE(returnLocalVariable1);
TEST_CASE(returnLocalVariable2);
@ -230,7 +231,7 @@ private:
ASSERT_EQUALS(std::string(""), errout.str());
}
void testassign()
void testassign1() // Ticket #1819
{
check("void f(EventPtr *eventP, ActionPtr **actionsP) {\n"
" EventPtr event = *eventP;\n"
@ -239,6 +240,15 @@ private:
ASSERT_EQUALS("", errout.str());
}
void testassign2() // Ticket #2765
{
check("static void function(unsigned long **datap) {\n"
" struct my_s *mr = global_structure_pointer;\n"
" *datap = &mr->value;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void returnLocalVariable1()
{
check("char *foo()\n"