QL: Add tests for FieldOnlyUsedInCharPred.ql

This commit is contained in:
Tom Hvitved
2023-06-20 15:23:08 +02:00
parent 2253761eb0
commit 12c810c63d
3 changed files with 32 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
| FieldOnlyUsedInCharPred.qll:2:3:2:12 | FieldDecl | Field is only used in CharPred. |
| FieldOnlyUsedInCharPred.qll:22:3:22:11 | FieldDecl | Field is only used in CharPred. |

View File

@@ -0,0 +1,29 @@
class C1 extends int {
int field; // BAD
C1() {
this = field and
this = 0
}
}
class C2 extends C1 {
int field2; // GOOD
C2() {
this = field2 and
this = 0
}
int getField() { result = field2 }
}
class C3 extends int {
C1 field; // GOOD (overridden)
C3() { this = field }
}
class C4 extends C3 {
override C2 field; // GOOD (overriding)
}

View File

@@ -0,0 +1 @@
queries/style/FieldOnlyUsedInCharPred.ql