mirror of
https://github.com/github/codeql.git
synced 2026-05-05 21:55:19 +02:00
Java: Add test for range analysis
This commit is contained in:
41
java/ql/test/library-tests/dataflow/range-analysis/A.java
Normal file
41
java/ql/test/library-tests/dataflow/range-analysis/A.java
Normal file
@@ -0,0 +1,41 @@
|
||||
public class A {
|
||||
int f1(int x, int y) {
|
||||
if (x < 500) {
|
||||
if (x > 400) {
|
||||
return x;
|
||||
}
|
||||
|
||||
if (y - 2 == x && y > 300) {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
if (x != y + 1) {
|
||||
int sum = x + y; // x <= 400
|
||||
} else {
|
||||
if (y > 300) {
|
||||
int sum = x + y; // 302 <= x <= 400, y = x - 1, 301 <= y <= 399
|
||||
}
|
||||
}
|
||||
|
||||
if (x > 500) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int f2(int x, int y, int z) {
|
||||
if (x < 500) {
|
||||
if (x > 400) {
|
||||
return x;
|
||||
}
|
||||
|
||||
if (y == x - 1 && y > 300 && y + 2 == z && z == 350) {
|
||||
return x + y + z;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user