Fix MaxIntOrMaxUint.isBoundFor

It was wrong for strictnessOffset = 1 before.
This commit is contained in:
Owen Mansel-Chan
2023-12-17 06:16:33 +00:00
parent 36c4f5d1b2
commit e45e92eaa7
2 changed files with 5 additions and 10 deletions

View File

@@ -15,15 +15,11 @@ abstract private class MaxIntOrMaxUint extends DeclaredConstant {
*/
predicate isBoundFor(int b, int architectureBitSize, float strictnessOffset) {
// 2.pow(x) - 1 - strictnessOffset <= 2.pow(b) - 1
exists(int x |
x = this.getOrder(architectureBitSize) and
b = validBitSize() and
(
strictnessOffset = 0 and x <= b
or
strictnessOffset = 1 and x <= b - 1
)
)
// For the values that we are restricting `b` to, `strictnessOffset` has no
// effect on the result, so we can ignore it.
b = validBitSize() and
strictnessOffset = [0, 1] and
this.getOrder(architectureBitSize) <= b
}
}

View File

@@ -1,3 +1,2 @@
testFailures
| IncorrectIntegerConversion.go:497:15:497:15 | i | Unexpected result: hasValueFlow="i" |
failures