@@ -375,6 +375,16 @@ private class NarrowingCastExpr extends CastExpr {
375375 int getUpperBound ( ) { typeBound ( getType ( ) , _, result ) }
376376}
377377
378+ /** Holds if `e >= 1` as determined by sign analysis. */
379+ private predicate strictlyPositiveIntegralExpr ( Expr e ) {
380+ strictlyPositive ( e ) and e .getType ( ) instanceof IntegralType
381+ }
382+
383+ /** Holds if `e <= -1` as determined by sign analysis. */
384+ private predicate strictlyNegativeIntegralExpr ( Expr e ) {
385+ strictlyNegative ( e ) and e .getType ( ) instanceof IntegralType
386+ }
387+
378388/**
379389 * Holds if `e1 + delta` is a valid bound for `e2`.
380390 * - `upper = true` : `e2 <= e1 + delta`
@@ -400,13 +410,13 @@ private predicate boundFlowStep(Expr e2, Expr e1, int delta, boolean upper) {
400410 // `x instanceof ConstantIntegerExpr` is covered by valueFlowStep
401411 not x instanceof ConstantIntegerExpr and
402412 not e1 instanceof ConstantIntegerExpr and
403- if strictlyPositive ( x )
413+ if strictlyPositiveIntegralExpr ( x )
404414 then upper = false and delta = 1
405415 else
406416 if positive ( x )
407417 then upper = false and delta = 0
408418 else
409- if strictlyNegative ( x )
419+ if strictlyNegativeIntegralExpr ( x )
410420 then upper = true and delta = - 1
411421 else
412422 if negative ( x )
@@ -429,13 +439,13 @@ private predicate boundFlowStep(Expr e2, Expr e1, int delta, boolean upper) {
429439 |
430440 // `x instanceof ConstantIntegerExpr` is covered by valueFlowStep
431441 not x instanceof ConstantIntegerExpr and
432- if strictlyPositive ( x )
442+ if strictlyPositiveIntegralExpr ( x )
433443 then upper = true and delta = - 1
434444 else
435445 if positive ( x )
436446 then upper = true and delta = 0
437447 else
438- if strictlyNegative ( x )
448+ if strictlyNegativeIntegralExpr ( x )
439449 then upper = false and delta = 1
440450 else
441451 if negative ( x )
0 commit comments