Skip to content

Commit 36ca97e

Browse files
committed
Add exclusions to reduce FP
Predicate parameters that have a database type are excluded. Also, uses of the exists variable in an agreggation or another quantifier are excluded.
1 parent 7d0018c commit 36ca97e

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

ql/ql/src/queries/style/OmittableExists.ql

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,22 @@
1010

1111
import ql
1212

13+
class AggregateOrForQuantifier extends AstNode {
14+
AggregateOrForQuantifier() {
15+
this instanceof FullAggregate or this instanceof Forex or this instanceof Forall
16+
}
17+
}
18+
1319
from VarDecl existsArgument, VarAccess use
1420
where
1521
existsArgument = any(Exists e).getAnArgument() and
1622
use = unique( | | existsArgument.getAnAccess()) and
17-
exists(Call c, int argPos | c.getArgument(argPos) = use |
18-
existsArgument.getType() = c.getTarget().getParameterType(argPos).getASuperType*()
19-
)
23+
exists(Call c, int argPos, Type paramType |
24+
c.getArgument(argPos) = use and paramType = c.getTarget().getParameterType(argPos)
25+
|
26+
existsArgument.getType() = paramType.getASuperType*() and
27+
not paramType instanceof DatabaseType
28+
) and
29+
not use.getParent*() instanceof AggregateOrForQuantifier
2030
select existsArgument, "This exists variable can be omitted by using a don't-care expression $@.",
2131
use, "in this argument"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| Test.qll:10:10:10:14 | i | This exists variable can be omitted by using a don't-care expression $@. | Test.qll:10:29:10:29 | i | in this argument |
1+
| Test.qll:18:10:18:14 | i | This exists variable can be omitted by using a don't-care expression $@. | Test.qll:18:29:18:29 | i | in this argument |

ql/ql/test/queries/style/OmittableExists/Test.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@ predicate aPredicate(int i) { none() }
22

33
predicate anotherPredicate(int i) { none() }
44

5+
predicate yetAnotherPredicate(int i, int y) { none() }
6+
7+
predicate dbTypePredicate(@location l) { none() }
8+
59
class SmallInt extends int {
610
SmallInt() { this = [0 .. 10] }
711
}
812

13+
class Location extends @location {
14+
string toString() { result = "" }
15+
}
16+
917
predicate test() {
1018
exists(int i | aPredicate(i)) // BAD
1119
or
@@ -15,5 +23,13 @@ predicate test() {
1523
or
1624
exists(int i | aPredicate(i) and exists(int i2 | i = i2)) // GOOD
1725
or
26+
exists(int i | count(int y | yetAnotherPredicate(i, y)) > 0) // GOOD
27+
or
28+
exists(int i | forex(int y | yetAnotherPredicate(i, y))) // GOOD
29+
or
30+
exists(int i | forall(int y | yetAnotherPredicate(i, y))) // GOOD
31+
or
1832
exists(SmallInt i | aPredicate(i)) // GOOD
33+
or
34+
exists(Location l | dbTypePredicate(l)) // GOOD
1935
}

0 commit comments

Comments
 (0)