Fix FP with negative index and negated condition (#2081)
This commit is contained in:
parent
d4549217d0
commit
13df5b2413
|
@ -3894,6 +3894,7 @@ struct ValueFlowConditionHandler {
|
||||||
if (parent && (parent->str() == "!" || Token::simpleMatch(parent, "== false"))) {
|
if (parent && (parent->str() == "!" || Token::simpleMatch(parent, "== false"))) {
|
||||||
check_if = !check_if;
|
check_if = !check_if;
|
||||||
check_else = !check_else;
|
check_else = !check_else;
|
||||||
|
std::swap(cond.true_values, cond.false_values);
|
||||||
}
|
}
|
||||||
tok2 = parent;
|
tok2 = parent;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1379,6 +1379,14 @@ private:
|
||||||
" v[-11] = 123;\n"
|
" v[-11] = 123;\n"
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (error) Array index -11 is out of bounds.\n", errout.str());
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue