From 833865e7369cab4c21ae90d3a19f8e77f2ba76d7 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Thu, 1 Sep 2011 22:22:33 -0400 Subject: [PATCH] fix #3066 (False positive: Inconclusive: Assigning address of local auto-variable to a function parameter.) --- lib/checkautovariables.cpp | 2 +- test/testautovariables.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 390c333d3..a72f2a88e 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -118,7 +118,7 @@ void CheckAutoVariables::autoVariables() if (var1 && var1->isArgument() && Token::Match(var1->nameToken()->tokAt(-2), "%type% *")) { const Variable * var2 = symbolDatabase->getVariableFromVarId(tok->tokAt(6)->varId()); - if (var2 && var2->isLocal() && !var2->isStatic()) + if (var2 && var2->isLocal() && !var2->isStatic() && !Token::simpleMatch(var2->typeEndToken(), "*")) errorAutoVariableAssignment(tok->next(), _settings->inconclusive); } } diff --git a/test/testautovariables.cpp b/test/testautovariables.cpp index 5387d1c2f..18a8ebb56 100644 --- a/test/testautovariables.cpp +++ b/test/testautovariables.cpp @@ -73,6 +73,7 @@ private: TEST_CASE(testautovar4); // ticket #2928 TEST_CASE(testautovar5); // ticket #2926 TEST_CASE(testautovar6); // ticket #2931 + TEST_CASE(testautovar7); // ticket #3066 TEST_CASE(testautovar_array1); TEST_CASE(testautovar_array2); TEST_CASE(testautovar_return1); @@ -215,6 +216,17 @@ private: ASSERT_EQUALS("[test.cpp:4]: (error) Inconclusive: Assigning address of local auto-variable to a function parameter.\n", errout.str()); } + void testautovar7() // ticket #3066 + { + check("struct txt_scrollpane_s * TXT_NewScrollPane(struct txt_widget_s * target)\n" + "{\n" + " struct txt_scrollpane_s * scrollpane;\n" + " target->parent = &scrollpane->widget;\n" + " return scrollpane;\n" + "}", false); + ASSERT_EQUALS("", errout.str()); + } + void testautovar_array1() { check("void func1(int* arr[2])\n"