uninitialized struct member: changed severity from warning to error since it is UB

This commit is contained in:
Daniel Marjamäki 2013-01-17 23:18:37 +01:00
parent 2c6b383822
commit c59dab2738
1 changed files with 3 additions and 6 deletions

View File

@ -1082,7 +1082,7 @@ void CheckUninitVar::checkScope(const Scope* scope)
tok = tok->next(); tok = tok->next();
if (stdtype || i->isPointer()) if (stdtype || i->isPointer())
checkScopeForVariable(scope, tok, *i, NULL, NULL, NULL); checkScopeForVariable(scope, tok, *i, NULL, NULL, NULL);
if (_settings->experimental && _settings->isEnabled("style") && Token::Match(i->typeStartToken(), "struct %type% %var% ;")) { if (_settings->experimental && Token::Match(i->typeStartToken(), "struct %type% %var% ;")) {
const std::string structname(i->typeStartToken()->next()->str()); const std::string structname(i->typeStartToken()->next()->str());
const SymbolDatabase * symbolDatabase = _tokenizer->getSymbolDatabase(); const SymbolDatabase * symbolDatabase = _tokenizer->getSymbolDatabase();
for (std::size_t j = 0U; j < symbolDatabase->classAndStructScopes.size(); ++j) { for (std::size_t j = 0U; j < symbolDatabase->classAndStructScopes.size(); ++j) {
@ -1518,10 +1518,7 @@ void CheckUninitVar::uninitvarError(const Token *tok, const std::string &varname
void CheckUninitVar::uninitStructMemberError(const Token *tok, const std::string &membername) void CheckUninitVar::uninitStructMemberError(const Token *tok, const std::string &membername)
{ {
reportError(tok, reportError(tok,
Severity::warning, Severity::error,
"uninitStructMember", "uninitStructMember",
"Perhaps '" + membername + "' should be initialized before calling function.\n" "Uninitialized struct member: " + membername);
"The struct is not fully initialized, '" + membername + "' hasn't been initialized. "
"Using the struct in function call might be dangerous, unless you know for sure that the member "
"will not be used by the function.");
} }