Skip to content

Commit 441fbe3

Browse files
committed
Add Java test file for sign analysis
1 parent 4a3118b commit 441fbe3

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class A {
2+
int f1(int x, int y) {
3+
if (x < 0) {
4+
return x; // strictly negative
5+
}
6+
if (x < y) {
7+
return y; // y is strictly positive because of the bound on x above
8+
}
9+
10+
return 0;
11+
}
12+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| A.java:4:14:4:14 | x | negative strictlyNegative |
2+
| A.java:6:9:6:9 | x | positive |
3+
| A.java:7:14:7:14 | y | positive strictlyPositive |
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java
2+
import semmle.code.java.dataflow.SignAnalysis
3+
4+
string getASignString(Expr i) {
5+
positive(i) and
6+
result = "positive"
7+
or
8+
negative(i) and
9+
result = "negative"
10+
or
11+
strictlyPositive(i) and
12+
result = "strictlyPositive"
13+
or
14+
strictlyNegative(i) and
15+
result = "strictlyNegative"
16+
}
17+
18+
from Expr e
19+
select e, strictconcat(string s | s = getASignString(e) | s, " ")

0 commit comments

Comments
 (0)