Bug hunting; Clarify bughuntingUninit output for non-const parameters
This commit is contained in:
parent
8161baf1e9
commit
99cb65b4b2
|
@ -498,22 +498,25 @@ static void uninit(const Token *tok, const ExprEngine::Value &value, ExprEngine:
|
|||
|
||||
const std::string symbol = (tok->varId() > 0) ? ("$symbol:" + tok->str() + "\n") : std::string();
|
||||
|
||||
std::string constMessage;
|
||||
std::string errorId = "bughuntingUninit";
|
||||
|
||||
{
|
||||
const Token *vartok = tok;
|
||||
while (Token::simpleMatch(vartok, "."))
|
||||
vartok = vartok->previous();
|
||||
while (Token::Match(vartok, ".|["))
|
||||
vartok = vartok->astOperand1();
|
||||
const Variable *var = vartok ? vartok->variable() : nullptr;
|
||||
if (var && var->isArgument())
|
||||
errorId += "Arg";
|
||||
if (var && var->isArgument()) {
|
||||
errorId += "NonConstArg";
|
||||
constMessage = " (you can use 'const' to say data must be initialized)";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
dataBase->reportError(tok,
|
||||
Severity::SeverityType::error,
|
||||
errorId.c_str(),
|
||||
symbol + "Cannot determine that '" + uninitexpr + "' is initialized" + inconclusiveMessage,
|
||||
symbol + "Cannot determine that '" + uninitexpr + "' is initialized" + constMessage + inconclusiveMessage,
|
||||
CWE_USE_OF_UNINITIALIZED_VARIABLE,
|
||||
inconclusive,
|
||||
value.type == ExprEngine::ValueType::BailoutValue);
|
||||
|
|
|
@ -207,7 +207,7 @@ private:
|
|||
// constant parameters should point at initialized data
|
||||
|
||||
check("char foo(char id[]) { return id[0]; }");
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) Cannot determine that 'id[0]' is initialized\n", errout.str());
|
||||
ASSERT_EQUALS("[test.cpp:1]: (error) Cannot determine that 'id[0]' is initialized (you can use 'const' to say data must be initialized)\n", errout.str());
|
||||
|
||||
check("char foo(const char id[]) { return id[0]; }");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
|
Loading…
Reference in New Issue