Quick check to omit useless heavy matches

This commit is contained in:
Dmitry-Me 2015-09-03 13:09:57 +03:00
parent ea11e28ea3
commit 0f073ad27e
1 changed files with 3 additions and 0 deletions

View File

@ -2156,6 +2156,9 @@ void CheckOther::checkSignOfUnsignedVariable()
const Scope * scope = symbolDatabase->functionScopes[i]; const Scope * scope = symbolDatabase->functionScopes[i];
// check all the code in the function // check all the code in the function
for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) {
// Quick check to see if any of the matches below have any chances
if (!tok->varId() && tok->str() != "0")
continue;
if (Token::Match(tok, "%name% <|<= 0") && tok->varId() && !Token::Match(tok->tokAt(3), "+|-")) { if (Token::Match(tok, "%name% <|<= 0") && tok->varId() && !Token::Match(tok->tokAt(3), "+|-")) {
// TODO: handle a[10].b , a::b , (unsigned int)x , etc // TODO: handle a[10].b , a::b , (unsigned int)x , etc
const Token *prev = tok->previous(); const Token *prev = tok->previous();