Refactoring: Added utility function that determine if scope ends with a call to a noreturn function
This commit is contained in:
parent
996a109b14
commit
91874214d8
|
@ -942,11 +942,9 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
|
||||||
(Token::Match(tok2->link()->tokAt(-2), "[;{}.] %var% (") ||
|
(Token::Match(tok2->link()->tokAt(-2), "[;{}.] %var% (") ||
|
||||||
Token::Match(tok2->link()->tokAt(-5), "[;{}] ( * %var% ) ("))) {
|
Token::Match(tok2->link()->tokAt(-5), "[;{}] ( * %var% ) ("))) {
|
||||||
// noreturn function?
|
// noreturn function?
|
||||||
// If inside null pointer check we unknown function call, we must
|
bool unknown = false;
|
||||||
// assume that it can terminate the program and possible null pointer
|
if (_tokenizer->IsScopeNoReturn(tok2->tokAt(2), &unknown)) {
|
||||||
// error wont ever happen.
|
if (!unknown || !_settings->inconclusive) {
|
||||||
if (tok2->strAt(2) == "}") {
|
|
||||||
if (!_settings->inconclusive) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
inconclusive = true;
|
inconclusive = true;
|
||||||
|
|
|
@ -1097,11 +1097,8 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int
|
||||||
*possibleInit = true;
|
*possibleInit = true;
|
||||||
|
|
||||||
// might be a noreturn function..
|
// might be a noreturn function..
|
||||||
if (Token::simpleMatch(tok->tokAt(-2), ") ; }") &&
|
if (_tokenizer->IsScopeNoReturn(tok))
|
||||||
Token::Match(tok->linkAt(-2)->tokAt(-2), "[;{}] %var% (") &&
|
return true;
|
||||||
tok->linkAt(-2)->previous()->varId() == 0) {
|
|
||||||
ret = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8380,7 +8380,38 @@ void Tokenizer::simplifyStd()
|
||||||
// Helper functions for handling the tokens list
|
// Helper functions for handling the tokens list
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
bool Tokenizer::IsScopeNoReturn(const Token *endScopeToken, bool *unknown) const
|
||||||
|
{
|
||||||
|
if (unknown)
|
||||||
|
*unknown = false;
|
||||||
|
|
||||||
|
if (Token::simpleMatch(endScopeToken->tokAt(-2), ") ; }")) {
|
||||||
|
const Token *tok = endScopeToken->linkAt(-2)->previous();
|
||||||
|
|
||||||
|
// function pointer call..
|
||||||
|
if (tok && Token::Match(tok->tokAt(-4), "[;{}] ( * %var% )"))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (!tok->isName())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (tok->str() == "exit")
|
||||||
|
return true;
|
||||||
|
|
||||||
|
while (tok && (Token::Match(tok, "::|.") || tok->isName()))
|
||||||
|
tok = tok->previous();
|
||||||
|
|
||||||
|
if (Token::Match(tok, "[;{}]")) {
|
||||||
|
if (unknown)
|
||||||
|
*unknown = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,14 @@ public:
|
||||||
return !isC() && !isJavaOrCSharp();
|
return !isC() && !isJavaOrCSharp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if inner scope ends with a call to a noreturn function
|
||||||
|
* \param endScopeToken The '}' token
|
||||||
|
* \param unknown set to true if it's unknown if the scope is noreturn
|
||||||
|
* \return true if scope ends with a function call that might be 'noreturn'
|
||||||
|
*/
|
||||||
|
bool IsScopeNoReturn(const Token *endScopeToken, bool *unknown = 0) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tokenize code
|
* Tokenize code
|
||||||
* @param code input stream for code, e.g.
|
* @param code input stream for code, e.g.
|
||||||
|
|
Loading…
Reference in New Issue