File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed
cpp/ql/lib/semmle/code/cpp/commons Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -1069,22 +1069,25 @@ class FormatLiteral extends Literal {
1069
1069
or
1070
1070
// The second case uses range analysis to deduce a length that's shorter than the length
1071
1071
// of the number -2^31.
1072
- exists ( Expr arg , float lower |
1072
+ exists ( Expr arg , float lower , float upper |
1073
1073
arg = this .getUse ( ) .getConversionArgument ( n ) and
1074
- lower = lowerBound ( arg .getFullyConverted ( ) )
1074
+ lower = lowerBound ( arg .getFullyConverted ( ) ) and
1075
+ upper = upperBound ( arg .getFullyConverted ( ) )
1075
1076
|
1076
1077
cand =
1077
1078
max ( int cand0 |
1079
+ // Include the sign bit in the length if it can be negative
1078
1080
(
1079
- // Include the sign bit in the length of `lower` if it can be negative
1080
1081
if lower < 0
1081
1082
then cand0 = 1 + lengthInBase10 ( lower .abs ( ) )
1082
1083
else cand0 = lengthInBase10 ( lower )
1083
1084
)
1084
1085
or
1085
- // We don't care about the sign of `upper`: if `upper` is negative, then we know
1086
- // `lower` is also (possibly more) negative, and thus its length will be greater.
1087
- cand0 = lengthInBase10 ( upperBound ( arg .getFullyConverted ( ) ) )
1086
+ (
1087
+ if upper < 0
1088
+ then cand0 = 1 + lengthInBase10 ( upper .abs ( ) )
1089
+ else cand0 = lengthInBase10 ( upper )
1090
+ )
1088
1091
)
1089
1092
)
1090
1093
)
You can’t perform that action at this time.
0 commit comments