Fixed #8217 (Crash in isVariableChanged())

This commit is contained in:
Daniel Marjamäki 2017-09-14 15:45:15 +02:00
parent 6cfcf8610d
commit 927b14b60f
2 changed files with 11 additions and 1 deletions

View File

@ -620,12 +620,15 @@ void CheckCondition::multiCondition2()
if (!Token::simpleMatch(tok->linkAt(1), "} while ("))
break;
tok2 = tok->linkAt(1)->linkAt(2);
} else {
} else if (Token::Match(tok, "if|while (")) {
tok2 = tok->linkAt(1);
if (Token::simpleMatch(tok2, ") {"))
tok2 = tok2->linkAt(1);
if (!tok2)
break;
} else {
// Incomplete code
break;
}
bool changed = false;
for (std::set<unsigned int>::const_iterator it = vars.begin(); it != vars.end(); ++it) {

View File

@ -1808,6 +1808,13 @@ private:
"}");
ASSERT_EQUALS("[test.cpp:2] -> [test.cpp:4]: (warning) Identical condition 'x>100', second condition is always false\n", errout.str());
check("void f(int x) {\n" // #8217 - crash for incomplete code
" if (x > 100) { return; }\n"
" X(do);\n"
" if (x > 100) {}\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void f(const int *i) {\n"
" if (!i) return;\n"
" if (!num1tok) { *num1 = *num2; }\n"