@@ -44,42 +44,12 @@ class BitShiftExpr extends BinaryBitwiseOperation {
44
44
this instanceof LShiftExpr or
45
45
this instanceof RShiftExpr
46
46
}
47
-
48
- override string toString ( ) {
49
- if this instanceof LShiftExpr then result = "left-shift" else result = "right-shift"
50
- }
51
47
}
52
48
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
79
51
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
83
53
}
84
54
85
55
predicate isForbiddenShiftExpr ( BitShiftExpr shift , string message ) {
@@ -88,12 +58,12 @@ predicate isForbiddenShiftExpr(BitShiftExpr shift, string message) {
88
58
getPrecision ( shift .getLeftOperand ( ) .getUnderlyingType ( ) ) <=
89
59
upperBound ( shift .getRightOperand ( ) ) and
90
60
message =
91
- "The operand " + shift .getLeftOperand ( ) + " is " + shift + "ed by an expression " +
61
+ "The operand " + shift .getLeftOperand ( ) + " is shifted by an expression " +
92
62
shift .getRightOperand ( ) + " which is greater than or equal to in precision."
93
63
or
94
64
lowerBound ( shift .getRightOperand ( ) ) < 0 and
95
65
message =
96
- "The operand " + shift .getLeftOperand ( ) + " is " + shift + "ed by a negative expression " +
66
+ "The operand " + shift .getLeftOperand ( ) + " is shifted by a negative expression " +
97
67
shift .getRightOperand ( ) + "."
98
68
) and
99
69
/*
0 commit comments