| 1359 | } |
| 1360 | |
| 1361 | void CheckStlImpl::negativeIndex() |
| 1362 | { |
| 1363 | logChecker("CheckStl::negativeIndex"); |
| 1364 | |
| 1365 | // Negative index is out of bounds.. |
| 1366 | const SymbolDatabase* const symbolDatabase = mTokenizer->getSymbolDatabase(); |
| 1367 | for (const Scope * scope : symbolDatabase->functionScopes) { |
| 1368 | for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { |
| 1369 | if (!Token::Match(tok, "%var% [") || !tok->next()->astOperand2()) |
| 1370 | continue; |
| 1371 | const Variable * const var = tok->variable(); |
| 1372 | if (!var || tok == var->nameToken()) |
| 1373 | continue; |
| 1374 | const Library::Container * const container = mSettings.library.detectContainer(var->typeStartToken()); |
| 1375 | if (!container || !container->arrayLike_indexOp) |
| 1376 | continue; |
| 1377 | const ValueFlow::Value *index = tok->next()->astOperand2()->getValueLE(-1, mSettings); |
| 1378 | if (!index) |
| 1379 | continue; |
| 1380 | negativeIndexError(tok, *index); |
| 1381 | } |
| 1382 | } |
| 1383 | } |
| 1384 | |
| 1385 | void CheckStlImpl::negativeIndexError(const Token *tok, const ValueFlow::Value &index) |
| 1386 | { |
no test coverage detected