Bug hunting; Improved uninit checking
This commit is contained in:
parent
303cadf99f
commit
e6aa96d90f
|
@ -253,6 +253,8 @@ static void uninit(const Token *tok, const ExprEngine::Value &value, ExprEngine:
|
||||||
} else if (uninitData) {
|
} else if (uninitData) {
|
||||||
if (dataBase->settings->library.getFunction(parent->astOperand1()))
|
if (dataBase->settings->library.getFunction(parent->astOperand1()))
|
||||||
return;
|
return;
|
||||||
|
if (parent->astOperand1()->isKeyword())
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else if (uninitData)
|
} else if (uninitData)
|
||||||
return;
|
return;
|
||||||
|
@ -275,10 +277,15 @@ static void uninit(const Token *tok, const ExprEngine::Value &value, ExprEngine:
|
||||||
value.type == ExprEngine::ValueType::BailoutValue);
|
value.type == ExprEngine::ValueType::BailoutValue);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string uninitexpr = tok->expressionString();
|
||||||
|
if (uninitData)
|
||||||
|
uninitexpr += "[0]";
|
||||||
|
|
||||||
dataBase->reportError(tok,
|
dataBase->reportError(tok,
|
||||||
Severity::SeverityType::error,
|
Severity::SeverityType::error,
|
||||||
"bughuntingUninit",
|
"bughuntingUninit",
|
||||||
"Cannot determine that '" + tok->expressionString() + "' is initialized",
|
"Cannot determine that '" + uninitexpr + "' is initialized",
|
||||||
CWE_USE_OF_UNINITIALIZED_VARIABLE,
|
CWE_USE_OF_UNINITIALIZED_VARIABLE,
|
||||||
false,
|
false,
|
||||||
value.type == ExprEngine::ValueType::BailoutValue);
|
value.type == ExprEngine::ValueType::BailoutValue);
|
||||||
|
|
|
@ -69,11 +69,14 @@ private:
|
||||||
|
|
||||||
check("char foo(const char id[]);\n"
|
check("char foo(const char id[]);\n"
|
||||||
"void bar() { char data[10]; foo(data); }");
|
"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"
|
check("char foo(char id[]);\n"
|
||||||
"void bar() { char data[10]; foo(data); }");
|
"void bar() { char data[10]; foo(data); }");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
|
check("void foo(int *p) { if (p) *p=0; }");
|
||||||
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ctu() {
|
void ctu() {
|
||||||
|
|
Loading…
Reference in New Issue