From 84ea0a2295c98ce6ffb6c3e3c195314c8e282b9e Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Sun, 25 Jul 2021 11:14:51 -0500 Subject: [PATCH] Refactor: Remove extra analysis of container sizes in conditions (#3357) --- lib/valueflow.cpp | 44 -------------------------------------------- 1 file changed, 44 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 452941062..60abb84f4 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -6426,50 +6426,6 @@ static void valueFlowContainerSize(TokenList *tokenlist, SymbolDatabase* symbold } } } - - // conditional conditionSize - for (const Scope &scope : symboldatabase->scopeList) { - if (scope.type != Scope::ScopeType::eIf) // TODO: while - continue; - for (const Token *tok = scope.classDef; tok && tok->str() != "{"; tok = tok->next()) { - if (!tok->isName() || !tok->valueType() || tok->valueType()->type != ValueType::CONTAINER || !tok->valueType()->container) - continue; - - const Token *conditionToken; - MathLib::bigint intval; - - if (Token::Match(tok, "%name% . %name% (")) { - if (tok->valueType()->container->getYield(tok->strAt(2)) == Library::Container::Yield::SIZE) { - const Token *parent = tok->tokAt(3)->astParent(); - if (!parent || !parent->isComparisonOp() || !parent->astOperand2()) - continue; - if (parent->astOperand1()->hasKnownIntValue()) - intval = parent->astOperand1()->values().front().intvalue; - else if (parent->astOperand2()->hasKnownIntValue()) - intval = parent->astOperand2()->values().front().intvalue; - else - continue; - conditionToken = parent; - } else if (tok->valueType()->container->getYield(tok->strAt(2)) == Library::Container::Yield::EMPTY) { - conditionToken = tok->tokAt(3); - intval = 0; - } else { - continue; - } - } else if (tok->valueType()->container->stdStringLike && Token::Match(tok, "%name% ==|!= %str%") && tok->next()->astOperand2() == tok->tokAt(2)) { - intval = Token::getStrLength(tok->tokAt(2)); - conditionToken = tok->next(); - } else { - continue; - } - - ValueFlow::Value value(conditionToken, intval); - value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE; - - // possible value before condition - valueFlowContainerReverse(const_cast(scope.classDef), tok, {value}, tokenlist, settings); - } - } } struct ContainerConditionHandler : ConditionHandler {