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

Method checkStruct

lib/checkuninitvar.cpp:235–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

233}
234
235void CheckUninitVarImpl::checkStruct(const Token *tok, const Variable &structvar)
236{
237 const Token *typeToken = structvar.typeStartToken();
238 while (Token::Match(typeToken, "%name% ::"))
239 typeToken = typeToken->tokAt(2);
240 const SymbolDatabase * symbolDatabase = mTokenizer->getSymbolDatabase();
241 for (const Scope *scope2 : symbolDatabase->classAndStructScopes) {
242 if (scope2->className == typeToken->str() && scope2->numConstructors == 0U) {
243 for (const Variable &var : scope2->varlist) {
244 if (var.isStatic() || var.hasDefault() || var.isArray() ||
245 (!mTokenizer->isC() && var.isClass() && (!var.type() || var.type()->needInitialization != Type::NeedInitialization::True)))
246 continue;
247
248 // is the variable declared in a inner union?
249 bool innerunion = false;
250 for (const Scope *innerScope : scope2->nestedList) {
251 if (innerScope->type == ScopeType::eUnion) {
252 if (var.typeStartToken()->linenr() >= innerScope->bodyStart->linenr() &&
253 var.typeStartToken()->linenr() <= innerScope->bodyEnd->linenr()) {
254 innerunion = true;
255 break;
256 }
257 }
258 }
259
260 if (!innerunion) {
261 Alloc alloc = NO_ALLOC;
262 const Token *tok2 = tok;
263 if (tok->str() == "}")
264 tok2 = tok2->next();
265 std::map<nonneg int, VariableValue> variableValue = getVariableValues(structvar.typeStartToken());
266 checkScopeForVariable(tok2, structvar, nullptr, nullptr, &alloc, var.name(), variableValue);
267 }
268 }
269 }
270 }
271}
272
273static VariableValue operator!(VariableValue v)
274{

Callers

nothing calls this directly

Calls 9

getVariableValuesFunction · 0.85
isArrayMethod · 0.80
isCMethod · 0.80
isClassMethod · 0.80
typeMethod · 0.80
nextMethod · 0.80
tokAtMethod · 0.45
strMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected