Restore code in checkVariableScope. Fixes false negative

This commit is contained in:
Daniel Marjamäki 2018-07-01 22:31:45 +02:00
parent bb73a741a8
commit 24dd4c9c26
2 changed files with 12 additions and 1 deletions

View File

@ -1097,7 +1097,7 @@ void CheckOther::checkVariableScope()
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
for (const Variable* var : symbolDatabase->variableList()) { for (const Variable* var : symbolDatabase->variableList()) {
if (!var || !var->isLocal() || (!var->isPointer() && !var->isReference() && var->valueType()->type <= ValueType::Type::RECORD)) if (!var || !var->isLocal() || (!var->isPointer() && !var->isReference() && !var->typeStartToken()->isStandardType()))
continue; continue;
if (var->isConst()) if (var->isConst())

View File

@ -83,6 +83,7 @@ private:
TEST_CASE(varScope22); // Ticket #5684 TEST_CASE(varScope22); // Ticket #5684
TEST_CASE(varScope23); // Ticket #6154 TEST_CASE(varScope23); // Ticket #6154
TEST_CASE(varScope24); // pointer / reference TEST_CASE(varScope24); // pointer / reference
TEST_CASE(varScope25); // time_t
TEST_CASE(oldStylePointerCast); TEST_CASE(oldStylePointerCast);
TEST_CASE(invalidPointerCast); TEST_CASE(invalidPointerCast);
@ -1159,6 +1160,16 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void varScope25() {
check("void f() {\n"
" time_t currtime;\n"
" if (a) {\n"
" currtime = time(&dummy);\n"
" if (currtime > t) {}\n"
" }\n"
"}", "test.c");
ASSERT_EQUALS("[test.c:2]: (style) The scope of the variable 'currtime' can be reduced.\n", errout.str());
}
void checkOldStylePointerCast(const char code[]) { void checkOldStylePointerCast(const char code[]) {
// Clear the error buffer.. // Clear the error buffer..
errout.str(""); errout.str("");