Skip to content

Commit 1e3ab52

Browse files
committed
ruby: tidy up methodSignatureSuccessorNodeRanked predicate
1 parent 08fa397 commit 1e3ab52

File tree

1 file changed

+17
-10
lines changed
  • ruby/ql/lib/codeql/ruby/experimental

1 file changed

+17
-10
lines changed

ruby/ql/lib/codeql/ruby/experimental/Rbi.qll

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,18 +205,25 @@ module Rbi {
205205
abstract ParameterType getAParameterType();
206206
}
207207

208+
private predicate isMethodSignatureCallNode(CfgNode n) {
209+
exists(MethodSignatureCall sig | sig.asExpr() = n)
210+
}
211+
208212
/**
209-
* Holds if `n` is the `r`th transitive successor node of `sig` where there are
210-
* no intervening `MethodSignatureCall`s.
213+
* Holds if `n` is the `i`th transitive successor node of `sigNode` where there
214+
* are no intervening nodes corresponding to `MethodSignatureCall`s.
211215
*/
212-
private predicate methodSignatureSuccessorNodeRanked(MethodSignatureCall sig, CfgNode n, int r) {
213-
exists(CfgNode p2 | not exists(MethodSignatureCall s | s.asExpr() = p2) |
214-
r = 1 and p2 = sig.asExpr().getASuccessor() and p2 = n
215-
or
216-
// set an arbitrary limit on how long the successor chain can be
217-
r = [2 .. 6] and
218-
methodSignatureSuccessorNodeRanked(sig, p2, r - 1) and
219-
n = p2.getASuccessor()
216+
private predicate methodSignatureSuccessorNodeRanked(MethodSignatureCall sig, CfgNode n, int i) {
217+
// direct successor
218+
i = 1 and
219+
n = sig.asExpr().getASuccessor() and
220+
not isMethodSignatureCallNode(n)
221+
or
222+
// transitive successor
223+
i > 1 and
224+
exists(CfgNode np | n = np.getASuccessor() |
225+
methodSignatureSuccessorNodeRanked(sig, np, i - 1) and
226+
not isMethodSignatureCallNode(np)
220227
)
221228
}
222229

0 commit comments

Comments
 (0)