Repository navigation
fix signed overflow in calculate() and MathLib constant folding #9030
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
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 |
|---|---|---|
|
|
@@ -371,7 +371,7 @@ struct ValueFlowAnalyzer : Analyzer { | |
| const std::string opName(inc ? "incremented" : "decremented"); | ||
| if (d == Direction::Reverse) | ||
| inc = !inc; | ||
| value->intvalue += (inc ? 1 : -1); | ||
| value->intvalue = calculateArithmetic<MathLib::bigint>(inc ? '+' : '-', value->intvalue, 1); | ||
|
Contributor
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 fixes the void f() {
long long x = 0x7fffffffffffffff;
long long y = ++x;
}Under
|
||
|
|
||
| /* Truncate value */ | ||
| const ValueType *dst = tok->valueType(); | ||
|
|
||
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.
AI review
Another signed overflow is left that the PR does not cover:
solveExprValueinlib/valueflow.cpp:6287(value.intvalue -= intval;) and:6296(value.intvalue += intval;).Under UBSan this gives:
The same chain with three
- 0x7fffffffffffffffsteps hits line 6296. If the goal is a testrunner that is clean with the sanitizer turned on, these sites need the helper as well.