Skip to content

Commit 207d908

Browse files
committed
Tidy up overall
1 parent ea31308 commit 207d908

File tree

5 files changed

+173
-298
lines changed

5 files changed

+173
-298
lines changed

c/cert/src/rules/INT34-C/ExprShiftedbyNegativeOrGreaterPrecisionOperand.ql

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -44,42 +44,12 @@ class BitShiftExpr extends BinaryBitwiseOperation {
4444
this instanceof LShiftExpr or
4545
this instanceof RShiftExpr
4646
}
47-
48-
override string toString() {
49-
if this instanceof LShiftExpr then result = "left-shift" else result = "right-shift"
50-
}
5147
}
5248

53-
int getPrecision(BuiltInType type) {
54-
type.(CharType).isExplicitlyUnsigned() and result = type.(CharType).getSize() * 8
55-
or
56-
type.(ShortType).isExplicitlyUnsigned() and result = type.(ShortType).getSize() * 8
57-
or
58-
type.(IntType).isExplicitlyUnsigned() and result = type.(IntType).getSize() * 8
59-
or
60-
type.(LongType).isExplicitlyUnsigned() and result = type.(LongType).getSize() * 8
61-
or
62-
type.(LongLongType).isExplicitlyUnsigned() and result = type.(LongLongType).getSize() * 8
63-
or
64-
type instanceof CharType and
65-
not type.(CharType).isExplicitlyUnsigned() and
66-
result = type.(CharType).getSize() * 8 - 1
67-
or
68-
type instanceof ShortType and
69-
not type.(ShortType).isExplicitlyUnsigned() and
70-
result = type.(ShortType).getSize() * 8 - 1
71-
or
72-
type instanceof IntType and
73-
not type.(IntType).isExplicitlyUnsigned() and
74-
result = type.(IntType).getSize() * 8 - 1
75-
or
76-
type instanceof LongType and
77-
not type.(LongType).isExplicitlyUnsigned() and
78-
result = type.(LongType).getSize() * 8 - 1
49+
int getPrecision(IntegralType type) {
50+
type.isExplicitlyUnsigned() and result = type.getSize() * 8
7951
or
80-
type instanceof LongLongType and
81-
not type.(LongLongType).isExplicitlyUnsigned() and
82-
result = type.(LongLongType).getSize() * 8 - 1
52+
type.isExplicitlySigned() and result = type.getSize() * 8 - 1
8353
}
8454

8555
predicate isForbiddenShiftExpr(BitShiftExpr shift, string message) {
@@ -88,12 +58,12 @@ predicate isForbiddenShiftExpr(BitShiftExpr shift, string message) {
8858
getPrecision(shift.getLeftOperand().getUnderlyingType()) <=
8959
upperBound(shift.getRightOperand()) and
9060
message =
91-
"The operand " + shift.getLeftOperand() + " is " + shift + "ed by an expression " +
61+
"The operand " + shift.getLeftOperand() + " is shifted by an expression " +
9262
shift.getRightOperand() + " which is greater than or equal to in precision."
9363
or
9464
lowerBound(shift.getRightOperand()) < 0 and
9565
message =
96-
"The operand " + shift.getLeftOperand() + " is " + shift + "ed by a negative expression " +
66+
"The operand " + shift.getLeftOperand() + " is shifted by a negative expression " +
9767
shift.getRightOperand() + "."
9868
) and
9969
/*

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ class StdIntIntPtrType extends Type {
3030
this.getName().regexpMatch("u?intptr_t")
3131
)
3232
}
33-
34-
override string toString() {
35-
if this.getName() = "uintptr_t" then result = "uintptr_t" else result = "intptr_t"
36-
}
3733
}
3834

3935
/**

0 commit comments

Comments
 (0)