Fix FP with negative index and negated condition (#2081)

This commit is contained in:
Paul Fultz II 2019-08-13 23:32:31 -05:00 committed by Daniel Marjamäki
parent d4549217d0
commit 13df5b2413
2 changed files with 9 additions and 0 deletions

View File

@ -3894,6 +3894,7 @@ struct ValueFlowConditionHandler {
if (parent && (parent->str() == "!" || Token::simpleMatch(parent, "== false"))) {
check_if = !check_if;
check_else = !check_else;
std::swap(cond.true_values, cond.false_values);
}
tok2 = parent;
}

View File

@ -1379,6 +1379,14 @@ private:
" v[-11] = 123;\n"
"}");
ASSERT_EQUALS("[test.cpp:2]: (error) Array index -11 is out of bounds.\n", errout.str());
check("int f(int x, const std::vector<int>& a) {\n"
" if (!(x < 5))\n"
" return a[x - 5];\n"
" else\n"
" return a[4 - x];\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}