Skip to content

Commit 9ddb2c6

Browse files
committed
Draft for INT36-C
1 parent 3d30316 commit 9ddb2c6

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

c/cert/src/rules/INT36-C/ConvertingAPointerToIntegerOrIntegerToPointer.ql

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,26 @@
1313
import cpp
1414
import codingstandards.c.cert
1515

16-
from
16+
/* 1. Declaring an integer variable to hold a pointer value */
17+
predicate integerVariableWithPointerValue(Variable var) {
18+
var.getUnderlyingType() instanceof IntType and
19+
var.getAnAssignedValue().getUnderlyingType() instanceof PointerType
20+
}
21+
22+
/* 2. Assigning an integer variable a pointer a pointer value */
23+
predicate assigningPointerValueToInteger(Assignment assign) {
24+
assign.getLValue().getUnderlyingType() instanceof IntType and
25+
assign.getRValue().getUnderlyingType() instanceof PointerType
26+
}
27+
28+
/* 3. Casting a pointer value to integer */
29+
predicate castingPointerToInteger(Cast cast) {
30+
cast.getExpr().getUnderlyingType() instanceof PointerType and
31+
cast.getUnderlyingType() instanceof PointerType
32+
}
33+
34+
from Variable x
1735
where
1836
not isExcluded(x, TypesPackage::convertingAPointerToIntegerOrIntegerToPointerQuery()) and
19-
select
37+
x.getType() instanceof PointerType
38+
select x, x.getType().getAPrimaryQlClass()

0 commit comments

Comments
 (0)