| 83 | } |
| 84 | |
| 85 | void CheckInternalImpl::checkRedundantTokCheck() |
| 86 | { |
| 87 | for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) { |
| 88 | if (Token::Match(tok, "&& Token :: simpleMatch|Match|findsimplematch|findmatch (")) { |
| 89 | // in code like |
| 90 | // if (tok->previous() && Token::match(tok->previous(), "bla")) {} |
| 91 | // the first tok->previous() check is redundant |
| 92 | const Token *astOp1 = tok->astOperand1(); |
| 93 | const Token *astOp2 = getArguments(tok->tokAt(3))[0]; |
| 94 | if (Token::simpleMatch(astOp1, "&&")) { |
| 95 | astOp1 = astOp1->astOperand2(); |
| 96 | } |
| 97 | if (astOp1->expressionString() == astOp2->expressionString()) { |
| 98 | checkRedundantTokCheckError(astOp2); |
| 99 | } |
| 100 | // if (!tok || !Token::match(tok, "foo")) |
| 101 | } else if (Token::Match(tok, "%oror% ! Token :: simpleMatch|Match|findsimplematch|findmatch (")) { |
| 102 | const Token *negTok = tok->next()->astParent()->astOperand1(); |
| 103 | if (Token::simpleMatch(negTok, "||")) { |
| 104 | negTok = negTok->astOperand2(); |
| 105 | } |
| 106 | // the first tok condition is negated |
| 107 | if (Token::simpleMatch(negTok, "!")) { |
| 108 | const Token *astOp1 = negTok->astOperand1(); |
| 109 | const Token *astOp2 = getArguments(tok->tokAt(4))[0]; |
| 110 | |
| 111 | if (astOp1->expressionString() == astOp2->expressionString()) { |
| 112 | checkRedundantTokCheckError(astOp2); |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | |
| 120 | void CheckInternalImpl::checkRedundantTokCheckError(const Token* tok) |
no test coverage detected