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
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 |
|---|---|---|
|
|
@@ -3633,7 +3633,7 @@ class TestSymbolDatabase : public TestFixture { | |
| ASSERT(fredScope != nullptr); | ||
|
|
||
| // The struct Fred has two functions, a constructor and a destructor | ||
| ASSERT_EQUALS(2U, fredScope->functionList.size()); | ||
| ASSERT_EQUALS(2U, fredScope->functionList.size()); // cppcheck-suppress nullPointer // see ticket #9747 | ||
|
Collaborator
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. This is an AI review. Take it with a grain of salt and feel free to reject it by resolving the comment. I confirmed that this suppression is needed because of the PR. With selfcheck's options ( To get a feel for how often that happens, I compared warnings for the merge base and the PR on lib/, cli/, test/cfg/, samples/, testsymboldatabase.cpp and testvalueflow.cpp (normal check level, style/warning/portability/performance, inconclusive). Both gave exactly the same 2407 warnings, so it doesn't look widespread. Some correlated-ternary probes such as 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. This suppression is only needed because of the valueflow change, so selfcheck now reports a new |
||
|
|
||
| // Get linenumbers where the bodies for the constructor and destructor are.. | ||
| unsigned int constructor = 0; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4325,6 +4325,26 @@ 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); | ||
|
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. The ticket is about an |
||
| } | ||
|
|
||
| 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.
Removing the "condition depends on only 1 variable / no function call" guard entirely means any possible value from either branch now goes up to
?whatever the condition is (several variables, function calls, values that carry a varId). That's a lot wider than what #15034 needs, so I'd expect new false positives (nullPointer, arrayIndexOutOfBounds, zerodiv) downstream. The selfcheck suppression added intestsymboldatabase.cppsuggests this has already happened. Could the guard be relaxed just for the case in the ticket, where the branch values come from the same variable that's in the condition, instead of being dropped? Please also add some negative tests, e.g.x ? y : 0whereyhas a possible value that's unrelated tox.