15
15
16
16
import cpp
17
17
import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
18
- import semmle.code.cpp.commons.Exclusions
19
18
20
19
/** Holds if the range contains no boundary values. */
21
20
predicate isRealRange ( Expr exp ) {
@@ -36,13 +35,19 @@ predicate isRealRange(Expr exp) {
36
35
upperBound ( exp ) != 32767 and
37
36
upperBound ( exp ) != 255 and
38
37
upperBound ( exp ) != 127 and
38
+ upperBound ( exp ) != 63 and
39
+ upperBound ( exp ) != 31 and
40
+ upperBound ( exp ) != 15 and
41
+ upperBound ( exp ) != 7 and
39
42
lowerBound ( exp ) != - 2147483648 and
40
43
lowerBound ( exp ) != - 268435456 and
41
44
lowerBound ( exp ) != - 33554432 and
42
45
lowerBound ( exp ) != - 8388608 and
43
46
lowerBound ( exp ) != - 65536 and
44
47
lowerBound ( exp ) != - 32768 and
45
- lowerBound ( exp ) != - 128
48
+ lowerBound ( exp ) != - 128 and
49
+ lowerBound ( exp ) != 0 and
50
+ lowerBound ( exp ) != upperBound ( exp )
46
51
or
47
52
lowerBound ( exp ) = 0 and
48
53
upperBound ( exp ) = 1
@@ -124,7 +129,12 @@ predicate isCodeBeforeCase(SwitchStmt swtmp) {
124
129
from SwitchStmt sw , string msg
125
130
where
126
131
isRealRange ( sw .getExpr ( ) ) and
127
- isRealRange ( sw .getExpr ( ) .getAChild * ( ) ) and
132
+ not exists ( Expr exptmp |
133
+ exptmp = sw .getExpr ( ) .getAChild * ( ) and
134
+ not exptmp .isConstant ( ) and
135
+ not isRealRange ( exptmp )
136
+ ) and
137
+ ( sw .getASwitchCase ( ) .terminatesInBreakStmt ( ) or sw .getASwitchCase ( ) .terminatesInReturnStmt ( ) ) and
128
138
(
129
139
isNotAllSelected ( sw ) and msg = "The range of condition values is less than the selection."
130
140
or
0 commit comments