File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8707,10 +8707,12 @@ static MathLib::bigint valueFlowGetStrLength(const Token* tok)
87078707 return Token::getStrLength (tok);
87088708 if (astIsGenericChar (tok) || tok->tokType () == Token::eChar)
87098709 return 1 ;
8710- if (const ValueFlow::Value* v2 = tok->getKnownValue (ValueFlow::Value::ValueType::CONTAINER_SIZE))
8711- return v2->intvalue ;
8712- if (const ValueFlow::Value* v1 = tok->getKnownValue (ValueFlow::Value::ValueType::TOK))
8713- return valueFlowGetStrLength (v1->tokvalue );
8710+ if (const ValueFlow::Value* v = tok->getKnownValue (ValueFlow::Value::ValueType::CONTAINER_SIZE))
8711+ return v->intvalue ;
8712+ if (const ValueFlow::Value* v = tok->getKnownValue (ValueFlow::Value::ValueType::TOK)) {
8713+ if (v->tokvalue != tok)
8714+ return valueFlowGetStrLength (v->tokvalue );
8715+ }
87148716 return 0 ;
87158717}
87168718
Original file line number Diff line number Diff line change @@ -7397,6 +7397,18 @@ class TestValueFlow : public TestFixture {
73977397 " }\n "
73987398 " }" ;
73997399 valueOfTok (code, " path" );
7400+
7401+ code = " struct S {\n "
7402+ " std::string to_string() const {\n "
7403+ " return { this->p , (size_t)this->n };\n "
7404+ " }\n "
7405+ " const char* p;\n "
7406+ " int n;\n "
7407+ " };\n "
7408+ " void f(S s, std::string& str) {\n "
7409+ " str += s.to_string();\n "
7410+ " }\n " ;
7411+ valueOfTok (code, " s" );
74007412 }
74017413
74027414 void valueFlowUnknownMixedOperators () {
You can’t perform that action at this time.
0 commit comments