mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
Add Java test file for sign analysis
This commit is contained in:
12
java/ql/test/library-tests/dataflow/sign-analysis/A.java
Normal file
12
java/ql/test/library-tests/dataflow/sign-analysis/A.java
Normal file
@@ -0,0 +1,12 @@
|
||||
public class A {
|
||||
int f1(int x, int y) {
|
||||
if (x < 0) {
|
||||
return x; // strictly negative
|
||||
}
|
||||
if (x < y) {
|
||||
return y; // y is strictly positive because of the bound on x above
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
| A.java:4:14:4:14 | x | negative strictlyNegative |
|
||||
| A.java:6:9:6:9 | x | positive |
|
||||
| A.java:7:14:7:14 | y | positive strictlyPositive |
|
||||
@@ -0,0 +1,19 @@
|
||||
import java
|
||||
import semmle.code.java.dataflow.SignAnalysis
|
||||
|
||||
string getASignString(Expr i) {
|
||||
positive(i) and
|
||||
result = "positive"
|
||||
or
|
||||
negative(i) and
|
||||
result = "negative"
|
||||
or
|
||||
strictlyPositive(i) and
|
||||
result = "strictlyPositive"
|
||||
or
|
||||
strictlyNegative(i) and
|
||||
result = "strictlyNegative"
|
||||
}
|
||||
|
||||
from Expr e
|
||||
select e, strictconcat(string s | s = getASignString(e) | s, " ")
|
||||
Reference in New Issue
Block a user