Repository navigation
Fix #15034 FN arrayIndexOutOfBounds (ternary in subfunction) #8856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
50b9a36
67eb159
86f316f
55d8250
1406a57
bbd2441
72fa075
c9716c6
dff6214
7ae3a34
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4325,6 +4325,45 @@ class TestValueFlow : public TestFixture { | |
| "}\n"; | ||
| auto values = tokenValues(code, "s :", ValueFlow::Value::ValueType::FLOAT); | ||
| ASSERT_EQUALS(0, values.size()); | ||
|
|
||
| code = "int a[5];\n" // 15034 | ||
| "int g(int i) {\n" | ||
| " return a[i < 0 ? -i : i];\n" | ||
| "}\n" | ||
| "int f() {\n" | ||
| " return g(-5);\n" | ||
| "}\n"; | ||
| values = tokenValues(code, "?"); | ||
| ASSERT_EQUALS(2, values.size()); | ||
| auto it = values.begin(); | ||
| ASSERT_EQUALS_ENUM(ValueFlow::Value::ValueType::INT, it->valueType); | ||
| ASSERT_EQUALS(0, it->intvalue); | ||
| ASSERT_EQUALS_ENUM(ValueFlow::Value::Bound::Lower, it->bound); | ||
| ASSERT_EQUALS_ENUM(ValueFlow::Value::ValueKind::Possible, it->valueKind); | ||
| ++it; | ||
| ASSERT_EQUALS_ENUM(ValueFlow::Value::ValueType::INT, it->valueType); | ||
| ASSERT_EQUALS(5, it->intvalue); | ||
| ASSERT_EQUALS_ENUM(ValueFlow::Value::Bound::Point, it->bound); | ||
| ASSERT_EQUALS_ENUM(ValueFlow::Value::ValueKind::Possible, it->valueKind); | ||
|
|
||
| code = "int f(int a, int b) {\n" | ||
| " if (b <= 0)\n" | ||
| " return b;\n" | ||
| " int a = (a > 0) ? a : -a;\n" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AI review This snippet isn't valid C/C++: Also, the two values below are asserted with identical fields (SYMBOLIC, -1, Upper, Impossible), and |
||
| " return 1 / (a < b ? b : a);\n" | ||
| "}\n"; | ||
| values = tokenValues(code, "? b"); | ||
| ASSERT_EQUALS(2, values.size()); | ||
| it = values.begin(); | ||
| ASSERT_EQUALS_ENUM(ValueFlow::Value::ValueType::SYMBOLIC, it->valueType); | ||
| ASSERT_EQUALS(-1, it->intvalue); | ||
| ASSERT_EQUALS_ENUM(ValueFlow::Value::Bound::Upper, it->bound); | ||
| ASSERT_EQUALS_ENUM(ValueFlow::Value::ValueKind::Impossible, it->valueKind); | ||
| ++it; | ||
| ASSERT_EQUALS_ENUM(ValueFlow::Value::ValueType::SYMBOLIC, it->valueType); | ||
| ASSERT_EQUALS(-1, it->intvalue); | ||
| ASSERT_EQUALS_ENUM(ValueFlow::Value::Bound::Upper, it->bound); | ||
| ASSERT_EQUALS_ENUM(ValueFlow::Value::ValueKind::Impossible, it->valueKind); | ||
| } | ||
|
|
||
| void valueFlowForwardLambda() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ticket is about an
arrayIndexOutOfBoundsfalse negative, but there's no checker-level test for it. Please add the ticket example totestbufferoverrun.cpp, together with a negative case such asa[i < 0 ? 0 : i]called withg(-5), which must not warn.