@@ -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
8555predicate 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 /*
0 commit comments