Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8707,10 +8707,12 @@ static MathLib::bigint valueFlowGetStrLength(const Token* tok)
return Token::getStrLength(tok);
if (astIsGenericChar(tok) || tok->tokType() == Token::eChar)
return 1;
if (const ValueFlow::Value* v2 = tok->getKnownValue(ValueFlow::Value::ValueType::CONTAINER_SIZE))
return v2->intvalue;
if (const ValueFlow::Value* v1 = tok->getKnownValue(ValueFlow::Value::ValueType::TOK))
return valueFlowGetStrLength(v1->tokvalue);
if (const ValueFlow::Value* v = tok->getKnownValue(ValueFlow::Value::ValueType::CONTAINER_SIZE))
return v->intvalue;
if (const ValueFlow::Value* v = tok->getKnownValue(ValueFlow::Value::ValueType::TOK)) {
if (v->tokvalue != tok)
return valueFlowGetStrLength(v->tokvalue);
}
return 0;
}

Expand Down
12 changes: 12 additions & 0 deletions test/testvalueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7397,6 +7397,18 @@ class TestValueFlow : public TestFixture {
" }\n"
"}";
valueOfTok(code, "path");

code = "struct S {\n"
" std::string to_string() const {\n"
" return { this->p , (size_t)this->n };\n"
" }\n"
" const char* p;\n"
" int n;\n"
"};\n"
"void f(S s, std::string& str) {\n"
" str += s.to_string();\n"
"}\n";
valueOfTok(code, "s");
}

void valueFlowUnknownMixedOperators() {
Expand Down