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

Method checkRhs

lib/checkuninitvar.cpp:1107–1142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1105}
1106
1107void CheckUninitVarImpl::checkRhs(const Token *tok, const Variable &var, Alloc alloc, nonneg int number_of_if, const std::string &membervar)
1108{
1109 bool rhs = false;
1110 int indent = 0;
1111 while (nullptr != (tok = tok->next())) {
1112 if (tok->str() == "=")
1113 rhs = true;
1114 else if (rhs && tok->varId() == var.declarationId()) {
1115 if (membervar.empty() && isVariableUsage(tok, var.isPointer(), alloc))
1116 uninitvarError(tok, tok->str(), alloc);
1117 else if (!membervar.empty() && isMemberVariableUsage(tok, var.isPointer(), alloc, membervar))
1118 uninitStructMemberError(tok, tok->str() + "." + membervar);
1119 else if (Token::Match(tok, "%var% ="))
1120 break;
1121 else if (Token::Match(tok->previous(), "[(,&]"))
1122 break;
1123 } else if (tok->str() == ";" || (indent==0 && tok->str() == ","))
1124 break;
1125 else if (tok->str() == "(")
1126 ++indent;
1127 else if (tok->str() == ")") {
1128 if (indent == 0)
1129 break;
1130 --indent;
1131 } else if (tok->str() == "?" && tok->astOperand2()) {
1132 const bool used1 = isVariableUsed(tok->astOperand2()->astOperand1(), var);
1133 const bool used0 = isVariableUsed(tok->astOperand2()->astOperand2(), var);
1134 const bool err = (number_of_if == 0) ? (used1 || used0) : (used1 && used0);
1135 if (err)
1136 uninitvarError(tok, var.nameToken()->str(), alloc);
1137 break;
1138 } else if (isUnevaluated(tok))
1139 tok = tok->linkAt(1);
1140
1141 }
1142}
1143
1144static bool astIsLhs(const Token *tok)
1145{

Callers

nothing calls this directly

Calls 11

isVariableUsageFunction · 0.85
uninitvarErrorFunction · 0.85
isVariableUsedFunction · 0.85
isUnevaluatedFunction · 0.85
nextMethod · 0.80
astOperand2Method · 0.80
astOperand1Method · 0.80
linkAtMethod · 0.80
strMethod · 0.45
emptyMethod · 0.45
nameTokenMethod · 0.45

Tested by

no test coverage detected