mirror of
https://github.com/github/codeql.git
synced 2026-04-30 03:05:15 +02:00
Merge pull request #13972 from MathiasVP/range-analysis-for-sub-expr
C++: Support subtraction in the new range analysis
This commit is contained in:
@@ -95,3 +95,25 @@ void gotoLoop(bool b1, bool b2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void test_sub(int x, int y, int n) {
|
||||
if(x > 0 && x < 500) {
|
||||
if(y > 0 && y < 10) {
|
||||
range(x - y); // $ range=<=498 range=>=-8
|
||||
}
|
||||
|
||||
if(n > 0 && n < 100) {
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
range(n - i); // $ range=">=Phi: i-97" range=<=99 range=>=-97
|
||||
range(i - n); // $ range="<=Phi: i-1" range=">=Phi: i-99" range=<=97 range=>=-99
|
||||
}
|
||||
|
||||
for (int i = n; i != 0; i--)
|
||||
{
|
||||
range(n - i); // $ SPURIOUS: overflow=+
|
||||
range(i - n); // $ range=">=Phi: i-99"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user