@@ -275,8 +275,9 @@ class UpperBoundCheckGuard extends DataFlow::RelationalComparisonNode {
275
275
}
276
276
277
277
/**
278
- * Gets the constant value which this upper bound check ensures the
279
- * other value is less than or equal to.
278
+ * Holds if the upper bound check ensures the non-constant operand is less
279
+ * than or equal to the maximum value for `bitSize` and `isSigned`. In this
280
+ * case, the upper bound check is a barrier guard.
280
281
*/
281
282
predicate isBoundFor ( int bitSize , boolean isSigned ) {
282
283
bitSize = [ 8 , 16 , 32 ] and
@@ -288,18 +289,15 @@ class UpperBoundCheckGuard extends DataFlow::RelationalComparisonNode {
288
289
then strictnessOffset = 1
289
290
else strictnessOffset = 0
290
291
|
291
- (
292
- bound = expr .getAnOperand ( ) .getExactValue ( ) .toFloat ( )
293
- or
294
- exists ( DeclaredConstant maxint | maxint .hasQualifiedName ( "math" , "MaxInt" ) |
295
- expr .getAnOperand ( ) = maxint .getAReference ( ) and
296
- bound = getMaxIntValue ( 32 , true )
297
- )
298
- or
299
- exists ( DeclaredConstant maxuint | maxuint .hasQualifiedName ( "math" , "MaxUint" ) |
300
- expr .getAnOperand ( ) = maxuint .getAReference ( ) and
301
- bound = getMaxIntValue ( 32 , false )
302
- )
292
+ exists ( DeclaredConstant maxint , DeclaredConstant maxuint |
293
+ maxint .hasQualifiedName ( "math" , "MaxInt" ) and maxuint .hasQualifiedName ( "math" , "MaxUint" )
294
+ |
295
+ if expr .getAnOperand ( ) = maxint .getAReference ( )
296
+ then bound = getMaxIntValue ( 32 , true )
297
+ else
298
+ if expr .getAnOperand ( ) = maxuint .getAReference ( )
299
+ then bound = getMaxIntValue ( 32 , false )
300
+ else bound = expr .getAnOperand ( ) .getExactValue ( ) .toFloat ( )
303
301
) and
304
302
bound - strictnessOffset <= getMaxIntValue ( bitSize , isSigned )
305
303
)
0 commit comments