@@ -5640,6 +5640,11 @@ struct ContainerVariableForwardAnalyzer : VariableForwardAnalyzer {
56405640 if (std::any_of (rhs->values ().begin (), rhs->values ().end (), [&](const ValueFlow::Value &rhsval) { return rhsval.isKnown () && rhsval.isContainerSizeValue (); }))
56415641 return Action::Read | Action::Write;
56425642 }
5643+ } else if (Token::Match (tok, " %name% . %name% (" )) {
5644+ Library::Container::Action action = tok->valueType ()->container ->getAction (tok->strAt (2 ));
5645+ if (action == Library::Container::Action::PUSH || action == Library::Container::Action::POP)
5646+ return Action::Read | Action::Write;
5647+ const Token* arg = tok->tokAt (4 );
56435648 }
56445649 return Action::None;
56455650 }
@@ -5664,6 +5669,12 @@ struct ContainerVariableForwardAnalyzer : VariableForwardAnalyzer {
56645669 }
56655670 }
56665671 }
5672+ } else if (Token::Match (tok, " %name% . %name% (" )) {
5673+ Library::Container::Action action = tok->valueType ()->container ->getAction (tok->strAt (2 ));
5674+ if (action == Library::Container::Action::PUSH)
5675+ value->intvalue ++;
5676+ if (action == Library::Container::Action::POP)
5677+ value->intvalue --;
56675678 }
56685679 }
56695680
@@ -5885,6 +5896,19 @@ static void valueFlowContainerSize(TokenList *tokenlist, SymbolDatabase* symbold
58855896 value.setKnown ();
58865897 valueFlowContainerForward (containerTok->next (), containerTok->variable (), value, tokenlist);
58875898 }
5899+ } else if (Token::Match (tok, " %var% . %name% (" ) && tok->valueType () && tok->valueType ()->container ) {
5900+ Library::Container::Action action = tok->valueType ()->container ->getAction (tok->strAt (2 ));
5901+ if (action == Library::Container::Action::CLEAR) {
5902+ ValueFlow::Value value (0 );
5903+ value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE;
5904+ value.setKnown ();
5905+ valueFlowContainerForward (tok->next (), tok->variable (), value, tokenlist);
5906+ } else if (action == Library::Container::Action::RESIZE && tok->tokAt (4 )->hasKnownIntValue ()) {
5907+ ValueFlow::Value value (tok->tokAt (4 )->values ().front ());
5908+ value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE;
5909+ value.setKnown ();
5910+ valueFlowContainerForward (tok->next (), tok->variable (), value, tokenlist);
5911+ }
58885912 }
58895913 }
58905914 }
0 commit comments