Fix issue 8842: Crash in valueFlowTerminatingCondition on incomplete code (#1480)

This commit is contained in:
Paul Fultz II 2018-11-13 23:23:45 -06:00 committed by Daniel Marjamäki
parent e839001f3d
commit f0c86b9d14
2 changed files with 12 additions and 0 deletions

View File

@ -1136,6 +1136,8 @@ static void valueFlowTerminatingCondition(TokenList *tokenlist, SymbolDatabase*
const Variable * var = tok2->variable();
if (!var)
continue;
if(!var->scope())
continue;
const Token * endToken = var->scope()->bodyEnd;
if (!var->isLocal() && !var->isConst() && !var->isArgument()) {
bail = true;

View File

@ -2693,6 +2693,16 @@ private:
" return;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// 8842 crash
check("class a {\n"
" int b;\n"
" c(b);\n"
" void f() {\n"
" if (b) return;\n"
" }\n"
"};\n");
ASSERT_EQUALS("", errout.str());
}
void multiConditionAlwaysTrue() {