Skip to content

Commit a8178be

Browse files
committed
Improve empty-array-ignored-dimensions.ql
Tested query with Variant Analysis and had a few results, though only in contrived test code apparently.
1 parent aae1644 commit a8178be

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

codeql-custom-queries-java/not-tested-queries/empty-array-ignored-dimensions.ql renamed to codeql-custom-queries-java/queries/likely-bugs/empty-array-ignored-dimensions.ql

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
* which indicates that the code might not behave the way it was originally
66
* designed:
77
* `new int[0][10][getSize()]` is the same as
8-
* ```
8+
* ```java
99
* getSize()
1010
* new int[0][][];
1111
* ```
12+
*
13+
* @kind problem
1214
*/
1315

1416
import java
@@ -19,13 +21,11 @@ class ZeroConstant extends CompileTimeConstantExpr {
1921
}
2022
}
2123

22-
from ArrayCreationExpr newArrayExpr
24+
from ArrayCreationExpr newArrayExpr, ZeroConstant zeroDimExpr, Expr otherDimExpr
2325
where
24-
exists (ZeroConstant zeroDimExpr, Expr otherDimExpr |
25-
zeroDimExpr = newArrayExpr.getADimension()
26-
and otherDimExpr = newArrayExpr.getADimension()
27-
// otherDimExpr appears behind 0 dim expression
28-
and zeroDimExpr.getIndex() < otherDimExpr.getIndex()
29-
and not otherDimExpr instanceof ZeroConstant
30-
)
31-
select newArrayExpr
26+
zeroDimExpr = newArrayExpr.getADimension()
27+
and otherDimExpr = newArrayExpr.getADimension()
28+
// otherDimExpr appears behind 0 dim expression
29+
and zeroDimExpr.getIndex() < otherDimExpr.getIndex()
30+
and not otherDimExpr instanceof ZeroConstant
31+
select otherDimExpr, "Pointless dimension argument because enclosing array has $@", zeroDimExpr, "size 0"

0 commit comments

Comments
 (0)