@@ -781,9 +781,11 @@ static void valueFlowTypeTraits(TokenList& tokenlist, const Settings& settings)
781781 eval[" is_reference" ] = [&](const std::vector<std::vector<const Token*>>& args) {
782782 if (args.size () != 1 )
783783 return ValueFlow::Value::unknown ();
784- ValueFlow::Value isRValue = eval[" is_rvalue_reference" ](args);
785- if (isRValue.isUninitValue () || isRValue.intvalue == 1 )
786- return isRValue;
784+ {
785+ ValueFlow::Value isRValue = eval[" is_rvalue_reference" ](args);
786+ if (isRValue.isUninitValue () || isRValue.intvalue == 1 )
787+ return isRValue;
788+ }
787789 return eval[" is_lvalue_reference" ](args);
788790 };
789791 for (Token* tok = tokenlist.front (); tok; tok = tok->next ()) {
@@ -5116,21 +5118,22 @@ static void valueFlowCondition(const ValuePtr<ConditionHandler>& handler,
51165118
51175119struct SimpleConditionHandler : ConditionHandler {
51185120 std::vector<Condition> parse (const Token* tok, const Settings& /* settings*/ ) const override {
5119-
5120- std::vector<Condition> conds;
5121- parseCompareEachInt (tok, [&](const Token* vartok, ValueFlow::Value true_value, ValueFlow::Value false_value) {
5122- if (vartok->hasKnownIntValue ())
5123- return ;
5124- if (vartok->str () == " =" && vartok->astOperand1 () && vartok->astOperand2 ())
5125- vartok = vartok->astOperand1 ();
5126- Condition cond;
5127- cond.true_values .push_back (std::move (true_value));
5128- cond.false_values .push_back (std::move (false_value));
5129- cond.vartok = vartok;
5130- conds.push_back (std::move (cond));
5131- });
5132- if (!conds.empty ())
5133- return conds;
5121+ {
5122+ std::vector<Condition> conds;
5123+ parseCompareEachInt (tok, [&](const Token* vartok, ValueFlow::Value true_value, ValueFlow::Value false_value) {
5124+ if (vartok->hasKnownIntValue ())
5125+ return ;
5126+ if (vartok->str () == " =" && vartok->astOperand1 () && vartok->astOperand2 ())
5127+ vartok = vartok->astOperand1 ();
5128+ Condition cond;
5129+ cond.true_values .push_back (std::move (true_value));
5130+ cond.false_values .push_back (std::move (false_value));
5131+ cond.vartok = vartok;
5132+ conds.push_back (std::move (cond));
5133+ });
5134+ if (!conds.empty ())
5135+ return conds;
5136+ }
51345137
51355138 const Token* vartok = nullptr ;
51365139
@@ -6637,9 +6640,11 @@ static std::vector<ValueFlow::Value> getContainerSizeFromConstructorArgs(const s
66376640 } else if (astIsContainer (args[0 ]) && args.size () == 1 ) { // copy constructor
66386641 return getContainerValues (args[0 ]);
66396642 } else if (isIteratorPair (args)) {
6640- std::vector<ValueFlow::Value> result = getContainerValues (args[0 ]);
6641- if (!result.empty ())
6642- return result;
6643+ {
6644+ std::vector<ValueFlow::Value> result = getContainerValues (args[0 ]);
6645+ if (!result.empty ())
6646+ return result;
6647+ }
66436648 // (ptr, ptr + size)
66446649 if (astIsPointer (args[0 ]) && args[0 ]->exprId () != 0 ) {
66456650 // (ptr, ptr) is empty
@@ -6940,21 +6945,23 @@ static void valueFlowContainerSize(const TokenList& tokenlist,
69406945struct ContainerConditionHandler : ConditionHandler {
69416946 std::vector<Condition> parse (const Token* tok, const Settings& settings) const override
69426947 {
6943- std::vector<Condition> conds;
6944- parseCompareEachInt (tok, [&](const Token* vartok, ValueFlow::Value true_value, ValueFlow::Value false_value) {
6945- vartok = settings.library .getContainerFromYield (vartok, Library::Container::Yield::SIZE);
6946- if (!vartok)
6947- return ;
6948- true_value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE;
6949- false_value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE;
6950- Condition cond;
6951- cond.true_values .push_back (std::move (true_value));
6952- cond.false_values .push_back (std::move (false_value));
6953- cond.vartok = vartok;
6954- conds.push_back (std::move (cond));
6955- });
6956- if (!conds.empty ())
6957- return conds;
6948+ {
6949+ std::vector<Condition> conds;
6950+ parseCompareEachInt (tok, [&](const Token* vartok, ValueFlow::Value true_value, ValueFlow::Value false_value) {
6951+ vartok = settings.library .getContainerFromYield (vartok, Library::Container::Yield::SIZE);
6952+ if (!vartok)
6953+ return ;
6954+ true_value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE;
6955+ false_value.valueType = ValueFlow::Value::ValueType::CONTAINER_SIZE;
6956+ Condition cond;
6957+ cond.true_values .push_back (std::move (true_value));
6958+ cond.false_values .push_back (std::move (false_value));
6959+ cond.vartok = vartok;
6960+ conds.push_back (std::move (cond));
6961+ });
6962+ if (!conds.empty ())
6963+ return conds;
6964+ }
69586965
69596966 const Token* vartok = nullptr ;
69606967
@@ -7645,10 +7652,12 @@ std::vector<ValueFlow::Value> ValueFlow::isOutOfBounds(const Value& size, const
76457652 ValueFlow::Value inBoundsValue = inferCondition (" <" , indexTok, size.intvalue );
76467653 if (inBoundsValue.isKnown () && inBoundsValue.intvalue != 0 )
76477654 return {};
7648- std::vector<ValueFlow::Value> result = isOutOfBoundsImpl (size, indexTok, false );
7649- if (!result.empty ())
7650- return result;
7655+ {
7656+ std::vector<ValueFlow::Value> result = isOutOfBoundsImpl (size, indexTok, false );
7657+ if (!result.empty ())
7658+ return result;
7659+ }
76517660 if (!possible)
7652- return result ;
7661+ return {} ;
76537662 return isOutOfBoundsImpl (size, indexTok, true );
76547663}
0 commit comments