Skip to content

Commit 865c050

Browse files
authored
Merge pull request github#13517 from hvitved/ql/field-only-used-in-charpred-fix
QL: Exclude overridden fields from `FieldOnlyUsedInCharPred.ql`
2 parents 19de7cd + d296256 commit 865c050

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

ql/ql/src/queries/style/FieldOnlyUsedInCharPred.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ where
2121
any(PredicateCall call |
2222
call.getEnclosingPredicate() = c.getCharPred() and call.getTarget() instanceof NewTypeBranch
2323
).getAnArgument() and
24-
not f.getVarDecl().overrides(_)
24+
not f.getVarDecl().overrides(_) and
25+
not any(FieldDecl other).getVarDecl().overrides(f.getVarDecl())
2526
select f, "Field is only used in CharPred."
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| FieldOnlyUsedInCharPred.qll:2:3:2:12 | FieldDecl | Field is only used in CharPred. |
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class C1 extends int {
2+
int field; // BAD
3+
4+
C1() {
5+
this = field and
6+
this = 0
7+
}
8+
}
9+
10+
class C2 extends C1 {
11+
int field2; // GOOD
12+
13+
C2() {
14+
this = field2 and
15+
this = 0
16+
}
17+
18+
int getField() { result = field2 }
19+
}
20+
21+
class C3 extends int {
22+
C1 field; // GOOD (overridden)
23+
24+
C3() { this = field }
25+
}
26+
27+
class C4 extends C3 {
28+
override C2 field; // GOOD (overriding)
29+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
queries/style/FieldOnlyUsedInCharPred.ql

0 commit comments

Comments
 (0)