| 394 | } |
| 395 | |
| 396 | bool CheckUninitVarImpl::checkScopeForVariable(const Token *tok, const Variable& var, bool * const possibleInit, bool * const noreturn, Alloc* const alloc, const std::string &membervar, std::map<nonneg int, VariableValue>& variableValue) |
| 397 | { |
| 398 | const bool suppressErrors(possibleInit && *possibleInit); // Assume that this is a variable declaration, rather than a fundef |
| 399 | const bool printDebug = mSettings.debugwarnings; |
| 400 | |
| 401 | if (possibleInit) |
| 402 | *possibleInit = false; |
| 403 | |
| 404 | int number_of_if = 0; |
| 405 | |
| 406 | if (var.declarationId() == 0U) |
| 407 | return true; |
| 408 | |
| 409 | for (; tok; tok = tok->next()) { |
| 410 | // End of scope.. |
| 411 | if (tok->str() == "}") { |
| 412 | if (number_of_if && possibleInit) |
| 413 | *possibleInit = true; |
| 414 | |
| 415 | // might be a noreturn function.. |
| 416 | if (mTokenizer->isScopeNoReturn(tok)) { |
| 417 | if (noreturn) |
| 418 | *noreturn = true; |
| 419 | return false; |
| 420 | } |
| 421 | |
| 422 | break; |
| 423 | } |
| 424 | |
| 425 | // Unconditional inner scope, try, lambda, init list |
| 426 | if (tok->str() == "{" && Token::Match(tok->previous(), ",|;|{|}|]|try")) { |
| 427 | bool possibleInitInner = false; |
| 428 | if (checkScopeForVariable(tok->next(), var, &possibleInitInner, noreturn, alloc, membervar, variableValue)) |
| 429 | return true; |
| 430 | tok = tok->link(); |
| 431 | if (possibleInitInner) { |
| 432 | number_of_if = 1; |
| 433 | if (possibleInit) |
| 434 | *possibleInit = true; |
| 435 | } |
| 436 | continue; |
| 437 | } |
| 438 | |
| 439 | // track values of other variables.. |
| 440 | if (Token::Match(tok->previous(), "[;{}.] %var% =")) { |
| 441 | if (tok->next()->astOperand2() && tok->next()->astOperand2()->hasKnownIntValue()) |
| 442 | variableValue[tok->varId()] = VariableValue(tok->next()->astOperand2()->getKnownIntValue()); |
| 443 | else if (Token::Match(tok->previous(), "[;{}] %var% = - %name% ;")) |
| 444 | variableValue[tok->varId()] = !VariableValue(0); |
| 445 | else |
| 446 | variableValue.erase(tok->varId()); |
| 447 | } |
| 448 | |
| 449 | // Inner scope.. |
| 450 | else if (Token::simpleMatch(tok, "if (")) { |
| 451 | bool alwaysTrue = false; |
| 452 | bool alwaysFalse = false; |
| 453 |
nothing calls this directly
no test coverage detected