Fix 11884: Hang in valueFlowGetStrLength (#5352)

This commit is contained in:
Paul Fultz II 2023-08-20 15:01:04 -05:00 committed by GitHub
parent 63811b2993
commit a5cfa85e0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 4 deletions

View File

@ -8707,10 +8707,12 @@ static MathLib::bigint valueFlowGetStrLength(const Token* tok)
return Token::getStrLength(tok); return Token::getStrLength(tok);
if (astIsGenericChar(tok) || tok->tokType() == Token::eChar) if (astIsGenericChar(tok) || tok->tokType() == Token::eChar)
return 1; return 1;
if (const ValueFlow::Value* v2 = tok->getKnownValue(ValueFlow::Value::ValueType::CONTAINER_SIZE)) if (const ValueFlow::Value* v = tok->getKnownValue(ValueFlow::Value::ValueType::CONTAINER_SIZE))
return v2->intvalue; return v->intvalue;
if (const ValueFlow::Value* v1 = tok->getKnownValue(ValueFlow::Value::ValueType::TOK)) if (const ValueFlow::Value* v = tok->getKnownValue(ValueFlow::Value::ValueType::TOK)) {
return valueFlowGetStrLength(v1->tokvalue); if (v->tokvalue != tok)
return valueFlowGetStrLength(v->tokvalue);
}
return 0; return 0;
} }

View File

@ -7397,6 +7397,18 @@ private:
" }\n" " }\n"
"}"; "}";
valueOfTok(code, "path"); 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() { void valueFlowUnknownMixedOperators() {