| 90 | } |
| 91 | |
| 92 | void CheckConditionImpl::assignIf() |
| 93 | { |
| 94 | if (!mSettings.severity.isEnabled(Severity::style) && !mSettings.isPremiumEnabled("assignIfError")) |
| 95 | return; |
| 96 | |
| 97 | logChecker("CheckCondition::assignIf"); // style |
| 98 | |
| 99 | for (const Token *tok = mTokenizer->tokens(); tok; tok = tok->next()) { |
| 100 | if (tok->str() != "=") |
| 101 | continue; |
| 102 | |
| 103 | if (Token::Match(tok->tokAt(-2), "[;{}] %var% =")) { |
| 104 | const Variable *var = tok->previous()->variable(); |
| 105 | if (var == nullptr) |
| 106 | continue; |
| 107 | |
| 108 | char bitop = '\0'; |
| 109 | MathLib::bigint num = 0; |
| 110 | |
| 111 | if (Token::Match(tok->next(), "%num% [&|]")) { |
| 112 | bitop = tok->strAt(2).at(0); |
| 113 | num = MathLib::toBigNumber(tok->tokAt(1)); |
| 114 | } else { |
| 115 | const Token *endToken = Token::findsimplematch(tok, ";"); |
| 116 | |
| 117 | // Casting address |
| 118 | if (endToken && Token::Match(endToken->tokAt(-4), "* ) & %any% ;")) |
| 119 | endToken = nullptr; |
| 120 | |
| 121 | if (endToken && Token::Match(endToken->tokAt(-2), "[&|] %num% ;")) { |
| 122 | bitop = endToken->strAt(-2).at(0); |
| 123 | num = MathLib::toBigNumber(endToken->tokAt(-1)); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | if (bitop == '\0') |
| 128 | continue; |
| 129 | |
| 130 | if (num < 0 && bitop == '|') |
| 131 | continue; |
| 132 | |
| 133 | assignIfParseScope(tok, tok->tokAt(4), var->declarationId(), var->isLocal(), bitop, num); |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | static bool isParameterChanged(const Token *partok) |
| 139 | { |
no test coverage detected