From bb5dfa58a1f594ca65de042843c393d86431f152 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Fri, 6 May 2011 19:26:04 -0400 Subject: [PATCH] fix #2765 (Non local address detected as address of local auto-variable) --- lib/checkautovariables.cpp | 4 ++-- test/testautovariables.cpp | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 27d302a0f..da305c699 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -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))) diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index fdcb6bc1f..afa2bb5c4 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -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"