| 304 | } |
| 305 | |
| 306 | bool CheckLeakAutoVarImpl::checkScope(const Token * const startToken, |
| 307 | VarInfo &varInfo, |
| 308 | std::set<int> notzero, |
| 309 | nonneg int recursiveCount) |
| 310 | { |
| 311 | #if ASAN |
| 312 | static const nonneg int recursiveLimit = 300; |
| 313 | #elif defined(__MINGW32__) |
| 314 | // testrunner crashes with stack overflow in CI |
| 315 | static constexpr nonneg int recursiveLimit = 600; |
| 316 | #else |
| 317 | static constexpr nonneg int recursiveLimit = 1000; |
| 318 | #endif |
| 319 | if (++recursiveCount > recursiveLimit) // maximum number of "else if ()" |
| 320 | throw InternalError(startToken, "Internal limit: CheckLeakAutoVar::checkScope() Maximum recursive count of 1000 reached.", InternalError::LIMIT); |
| 321 | |
| 322 | std::map<int, VarInfo::AllocInfo> &alloctype = varInfo.alloctype; |
| 323 | auto& possibleUsage = varInfo.possibleUsage; |
| 324 | const std::set<int> conditionalAlloc(varInfo.conditionalAlloc); |
| 325 | |
| 326 | // Parse all tokens |
| 327 | const Token * const endToken = startToken->link(); |
| 328 | for (const Token *tok = startToken; tok && tok != endToken; tok = tok->next()) { |
| 329 | if (!tok->scope()->isExecutable()) { |
| 330 | tok = tok->scope()->bodyEnd; |
| 331 | if (!tok) // Ticket #6666 (crash upon invalid code) |
| 332 | break; |
| 333 | } |
| 334 | |
| 335 | // check each token |
| 336 | { |
| 337 | const bool isInit = Token::Match(tok, "%var% {|(") && tok->variable() && tok == tok->variable()->nameToken() && tok->variable()->isPointer(); |
| 338 | const Token * nextTok = isInit ? nullptr : checkTokenInsideExpression(tok, varInfo); |
| 339 | if (nextTok) { |
| 340 | tok = nextTok; |
| 341 | continue; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | |
| 346 | // look for end of statement |
| 347 | const bool isInit = Token::Match(tok->tokAt(-1), "%var% {|(") && tok->tokAt(-1)->variable() && tok->tokAt(-1) == tok->tokAt(-1)->variable()->nameToken(); |
| 348 | if ((!Token::Match(tok, "[;{},]") || Token::Match(tok->next(), "[;{},]")) && !(isInit && tok->str() == "(")) |
| 349 | continue; |
| 350 | |
| 351 | if (Token::Match(tok, "[;{},] %var% [")) |
| 352 | continue; |
| 353 | |
| 354 | if (!isInit) |
| 355 | tok = tok->next(); |
| 356 | if (!tok || tok == endToken) |
| 357 | break; |
| 358 | |
| 359 | if (Token::Match(tok, "%name% (") && isUnevaluated(tok)) { |
| 360 | tok = tok->linkAt(1); |
| 361 | continue; |
| 362 | } |
| 363 |
nothing calls this directly
no test coverage detected