@@ -375,6 +375,16 @@ private class NarrowingCastExpr extends CastExpr {
375
375
int getUpperBound ( ) { typeBound ( getType ( ) , _, result ) }
376
376
}
377
377
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
+
378
388
/**
379
389
* Holds if `e1 + delta` is a valid bound for `e2`.
380
390
* - `upper = true` : `e2 <= e1 + delta`
@@ -400,13 +410,13 @@ private predicate boundFlowStep(Expr e2, Expr e1, int delta, boolean upper) {
400
410
// `x instanceof ConstantIntegerExpr` is covered by valueFlowStep
401
411
not x instanceof ConstantIntegerExpr and
402
412
not e1 instanceof ConstantIntegerExpr and
403
- if strictlyPositive ( x )
413
+ if strictlyPositiveIntegralExpr ( x )
404
414
then upper = false and delta = 1
405
415
else
406
416
if positive ( x )
407
417
then upper = false and delta = 0
408
418
else
409
- if strictlyNegative ( x )
419
+ if strictlyNegativeIntegralExpr ( x )
410
420
then upper = true and delta = - 1
411
421
else
412
422
if negative ( x )
@@ -429,13 +439,13 @@ private predicate boundFlowStep(Expr e2, Expr e1, int delta, boolean upper) {
429
439
|
430
440
// `x instanceof ConstantIntegerExpr` is covered by valueFlowStep
431
441
not x instanceof ConstantIntegerExpr and
432
- if strictlyPositive ( x )
442
+ if strictlyPositiveIntegralExpr ( x )
433
443
then upper = true and delta = - 1
434
444
else
435
445
if positive ( x )
436
446
then upper = true and delta = 0
437
447
else
438
- if strictlyNegative ( x )
448
+ if strictlyNegativeIntegralExpr ( x )
439
449
then upper = false and delta = 1
440
450
else
441
451
if negative ( x )
0 commit comments