Bug hunting; Improved uninit checking

This commit is contained in:
Daniel Marjamäki 2020-06-27 14:59:02 +02:00
parent 303cadf99f
commit e6aa96d90f
2 changed files with 12 additions and 2 deletions

View File

@ -253,6 +253,8 @@ static void uninit(const Token *tok, const ExprEngine::Value &value, ExprEngine:
} else if (uninitData) {
if (dataBase->settings->library.getFunction(parent->astOperand1()))
return;
if (parent->astOperand1()->isKeyword())
return;
}
} else if (uninitData)
return;
@ -275,10 +277,15 @@ static void uninit(const Token *tok, const ExprEngine::Value &value, ExprEngine:
value.type == ExprEngine::ValueType::BailoutValue);
return;
}
std::string uninitexpr = tok->expressionString();
if (uninitData)
uninitexpr += "[0]";
dataBase->reportError(tok,
Severity::SeverityType::error,
"bughuntingUninit",
"Cannot determine that '" + tok->expressionString() + "' is initialized",
"Cannot determine that '" + uninitexpr + "' is initialized",
CWE_USE_OF_UNINITIALIZED_VARIABLE,
false,
value.type == ExprEngine::ValueType::BailoutValue);

View File

@ -69,11 +69,14 @@ private:
check("char foo(const char id[]);\n"
"void bar() { char data[10]; foo(data); }");
ASSERT_EQUALS("[test.cpp:2]: (error) Cannot determine that 'data' is initialized\n", errout.str());
ASSERT_EQUALS("[test.cpp:2]: (error) Cannot determine that 'data[0]' is initialized\n", errout.str());
check("char foo(char id[]);\n"
"void bar() { char data[10]; foo(data); }");
ASSERT_EQUALS("", errout.str());
check("void foo(int *p) { if (p) *p=0; }");
ASSERT_EQUALS("", errout.str());
}
void ctu() {