Predicate pointlessComparison
Holds if cmp
is a comparison operation that always has the
result value
, and either
ss
isLeftIsSmaller
, and the left hand argument is always at mostleft
, the right hand argument at leastright
, andleft
is less than or equal toright
; orss
isRightIsSmaller
, and the left hand argument is always at leastleft
, the right hand argument at mostright
, andleft
is greater than or equal toright
.
For example, if the comparison x < y
is always true because
x <= 3
and 5 <= y
then
pointlessComparison(x < y, 3, 5, true, LeftIsSmaller)
holds.
Similarly, if the comparison x < y
is always false because x >= 9
and 7 >= y
then
pointlessComparison(x < y, 9, 7, false, RightIsSmaller)
holds.
Import path
import semmle.code.cpp.rangeanalysis.PointlessComparison
predicate
pointlessComparison
(
ComparisonOperation
cmp
,
float
left
,
float
right
,
boolean
value
,
SmallSide
ss
)