Fix FP: Set correct bounds for interval (#3411)

This commit is contained in:
Paul Fultz II 2021-08-21 14:17:05 -05:00 committed by GitHub
parent d30f42e0da
commit a0c37ceba2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -4545,14 +4545,14 @@ static std::vector<ValueFlow::Value> infer(const ValuePtr<InferModel>& model,
if (!diff.minvalue.empty()) { if (!diff.minvalue.empty()) {
ValueFlow::Value value(diff.minvalue.front() - 1); ValueFlow::Value value(diff.minvalue.front() - 1);
value.setImpossible(); value.setImpossible();
value.bound = ValueFlow::Value::Bound::Lower; value.bound = ValueFlow::Value::Bound::Upper;
addToErrorPath(value, diff.minRef); addToErrorPath(value, diff.minRef);
result.push_back(value); result.push_back(value);
} }
if (!diff.maxvalue.empty()) { if (!diff.maxvalue.empty()) {
ValueFlow::Value value(diff.maxvalue.front() + 1); ValueFlow::Value value(diff.maxvalue.front() + 1);
value.setImpossible(); value.setImpossible();
value.bound = ValueFlow::Value::Bound::Upper; value.bound = ValueFlow::Value::Bound::Lower;
addToErrorPath(value, diff.maxRef); addToErrorPath(value, diff.maxRef);
result.push_back(value); result.push_back(value);
} }

View File

@ -3787,6 +3787,14 @@ private:
check("bool f(bool a, bool b) { if(a && b && (!a)){} }"); check("bool f(bool a, bool b) { if(a && b && (!a)){} }");
ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (style) Condition '!a' is always false\n", errout.str()); ASSERT_EQUALS("[test.cpp:1] -> [test.cpp:1]: (style) Condition '!a' is always false\n", errout.str());
check("void f(int x, int y) {\n"
" if (x < y) {\n"
" auto z = y - x;\n"
" if (z < 1) {}\n"
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (style) Condition 'z<1' is always false\n", errout.str());
check("struct a {\n" check("struct a {\n"
" a *b() const;\n" " a *b() const;\n"
"} c;\n" "} c;\n"