Fix issue 9882: segfault in ForwardTraversal (#2785)

This commit is contained in:
Paul Fultz II 2020-09-08 13:14:10 -05:00 committed by GitHub
parent e802d85315
commit 5099ca3c8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -412,7 +412,7 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
if (value.isContainerSizeValue()) { if (value.isContainerSizeValue()) {
// .empty, .size, +"abc", +'a' // .empty, .size, +"abc", +'a'
if (parent->str() == "+") { if (parent->str() == "+" && parent->astOperand1() && parent->astOperand2()) {
for (const ValueFlow::Value &value1 : parent->astOperand1()->values()) { for (const ValueFlow::Value &value1 : parent->astOperand1()->values()) {
for (const ValueFlow::Value &value2 : parent->astOperand2()->values()) { for (const ValueFlow::Value &value2 : parent->astOperand2()->values()) {
if (value1.path != value2.path) if (value1.path != value2.path)

View File

@ -4715,6 +4715,15 @@ private:
" return x;\n" " return x;\n"
"}\n"; "}\n";
valueOfTok(code, "x"); valueOfTok(code, "x");
code = "void f() {\n"
" std::string a = b[c->d()];\n"
" if(a.empty()) {\n"
" INFO(std::string{\"a\"} + c->d());\n"
" INFO(std::string{\"b\"} + a);\n"
" }\n"
"}\n";
valueOfTok(code, "a");
} }
void valueFlowHang() { void valueFlowHang() {