Merge branch 'main' into lifetime-subfunction

This commit is contained in:
Paul 2020-09-08 13:18:01 -05:00
commit 8c425790f4
2 changed files with 23 additions and 3 deletions

View File

@ -412,7 +412,7 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value, const Setti
if (value.isContainerSizeValue()) {
// .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 &value2 : parent->astOperand2()->values()) {
if (value1.path != value2.path)
@ -3098,11 +3098,13 @@ std::vector<LifetimeToken> getLifetimeTokens(const Token* tok, bool escape, Valu
for (const ValueFlow::Value &v : vartok->values()) {
if (!v.isLocalLifetimeValue())
continue;
if (v.tokvalue == tok)
continue;
errorPath.insert(errorPath.end(), v.errorPath.begin(), v.errorPath.end());
return getLifetimeTokens(v.tokvalue, escape, std::move(errorPath));
return getLifetimeTokens(v.tokvalue, escape, std::move(errorPath), depth - 1);
}
} else {
return LifetimeToken::setAddressOf(getLifetimeTokens(vartok, escape, std::move(errorPath)),
return LifetimeToken::setAddressOf(getLifetimeTokens(vartok, escape, std::move(errorPath), depth - 1),
!(astIsContainer(vartok) && Token::simpleMatch(vartok->astParent(), "[")));
}
}

View File

@ -4706,6 +4706,15 @@ private:
"}\n";
valueOfTok(code, "x");
code = "void f(){\n"
" struct dwarf_data **pp;\n"
" for (pp = (struct dwarf_data **) (void *) &state->fileline_data;\n"
" *pp != NULL;\n"
" pp = &(*pp)->next)\n"
" ;\n"
"}\n";
valueOfTok(code, "x");
code = "void *foo(void *x);\n"
"void *foo(void *x)\n"
"{\n"
@ -4715,6 +4724,15 @@ private:
" return x;\n"
"}\n";
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() {