Fixed #3467 (False positive: Variable is not assigned a value (new))

This commit is contained in:
Daniel Marjamäki 2012-01-08 08:31:00 +01:00
parent 3c0ada52e6
commit 70c83d9ca9
2 changed files with 13 additions and 1 deletions

View File

@ -929,7 +929,7 @@ void CheckUnusedVar::checkFunctionVariableUsage()
unusedVariableError(usage._name, varname); unusedVariableError(usage._name, varname);
// variable has not been written but has been modified // variable has not been written but has been modified
else if (usage._modified && !usage._write) else if (usage._modified && !usage._write && !usage._allocateMemory)
unassignedVariableError(usage._name, varname); unassignedVariableError(usage._name, varname);
// variable has been written but not read // variable has been written but not read

View File

@ -99,6 +99,7 @@ private:
TEST_CASE(localvarstatic); TEST_CASE(localvarstatic);
TEST_CASE(localvardynamic1); TEST_CASE(localvardynamic1);
TEST_CASE(localvardynamic2); // ticket #2904 TEST_CASE(localvardynamic2); // ticket #2904
TEST_CASE(localvardynamic3); // ticket #3467
TEST_CASE(localvararray1); // ticket #2780 TEST_CASE(localvararray1); // ticket #2780
TEST_CASE(localvararray2); // ticket #3438 TEST_CASE(localvararray2); // ticket #3438
TEST_CASE(localvarstring1); TEST_CASE(localvarstring1);
@ -2863,6 +2864,17 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void localvardynamic3() {
// Ticket #3477 - False positive that 'data' is not assigned a value
functionVariableUsage("void foo() {\n"
" int* data = new int[100];\n"
" int* p = data;\n"
" for ( int i = 0; i < 10; ++i )\n"
" p++;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void localvararray1() { void localvararray1() {
functionVariableUsage("void foo() {\n" functionVariableUsage("void foo() {\n"
" int p[5];\n" " int p[5];\n"