File tree Expand file tree Collapse file tree 1 file changed +12
-9
lines changed
cpp/ql/src/semmle/code/cpp/stmts Expand file tree Collapse file tree 1 file changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -1136,6 +1136,11 @@ private predicate inForUpdate(Expr forUpdate, Expr child) {
1136
1136
exists ( Expr mid | inForUpdate ( forUpdate , mid ) and child .getParent ( ) = mid )
1137
1137
}
1138
1138
1139
+ /** Gets the `rnk`'th `case` statement in `b`. */
1140
+ private int indexOfSwitchCaseRank ( BlockStmt b , int rnk ) {
1141
+ result = rank [ rnk ] ( int i | b .getStmt ( i ) instanceof SwitchCase )
1142
+ }
1143
+
1139
1144
/**
1140
1145
* A C/C++ 'switch case' statement.
1141
1146
*
@@ -1331,16 +1336,14 @@ class SwitchCase extends Stmt, @stmt_switch_case {
1331
1336
* `default:` has results `{ x = 3; }, `x = 4;` and `break;`.
1332
1337
*/
1333
1338
Stmt getAStmt ( ) {
1334
- exists ( BlockStmt b , int i , int j |
1339
+ exists ( BlockStmt b , int rnk , int i |
1335
1340
b .getStmt ( i ) = this and
1336
- b .getStmt ( j ) = result and
1337
- i < j and
1338
- not result instanceof SwitchCase and
1339
- not exists ( SwitchCase sc , int k |
1340
- b .getStmt ( k ) = sc and
1341
- i < k and
1342
- j > k
1343
- )
1341
+ i = indexOfSwitchCaseRank ( b , rnk )
1342
+ |
1343
+ pragma [ only_bind_into ] ( b ) .getStmt ( [ i + 1 .. indexOfSwitchCaseRank ( b , rnk + 1 ) - 1 ] ) = result
1344
+ or
1345
+ not exists ( indexOfSwitchCaseRank ( b , rnk + 1 ) ) and
1346
+ b .getStmt ( [ i + 1 .. b .getNumStmt ( ) + 1 ] ) = result
1344
1347
)
1345
1348
}
1346
1349
You can’t perform that action at this time.
0 commit comments