MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / assignIf

Method assignIf

lib/checkcondition.cpp:92–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92void 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
138static bool isParameterChanged(const Token *partok)
139{

Callers 1

runChecksMethod · 0.80

Calls 8

findsimplematchFunction · 0.85
isPremiumEnabledMethod · 0.80
nextMethod · 0.80
variableMethod · 0.80
atMethod · 0.80
isEnabledMethod · 0.45
strMethod · 0.45
tokAtMethod · 0.45

Tested by

no test coverage detected