Skip to content

Commit 9ac526b

Browse files
committed
Ruby: change binding for getParameter/getKeywordParameter
1 parent 073493b commit 9ac526b

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

ruby/ql/lib/codeql/ruby/ApiGraphs.qll

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,25 +119,16 @@ module API {
119119
*/
120120
Node getReturn(string method) { result = this.getMethod(method).getReturn() }
121121

122-
private predicate hasParameterIndex(int n) {
123-
exists(string str |
124-
exists(this.getASuccessor(Label::parameterByStr(str))) and
125-
n = str.toInt()
126-
)
127-
}
128-
129122
/** Gets an API node representing the `n`th positional parameter. */
123+
pragma[nomagic]
130124
Node getParameter(int n) {
131-
result = this.getASuccessor(Label::parameter(n)) and this.hasParameterIndex(n)
132-
}
133-
134-
private predicate hasKeywordParameter(string name) {
135-
exists(this.getASuccessor(Label::keywordParameter(name)))
125+
result = this.getASuccessor(Label::parameter(n))
136126
}
137127

138128
/** Gets an API node representing the given keyword parameter. */
129+
pragma[nomagic]
139130
Node getKeywordParameter(string name) {
140-
result = this.getASuccessor(Label::keywordParameter(name)) and this.hasKeywordParameter(name)
131+
result = this.getASuccessor(Label::keywordParameter(name))
141132
}
142133

143134
/** Gets an API node representing the block parameter. */
@@ -641,7 +632,14 @@ private module Label {
641632

642633
/** Gets the label representing the `n`th positional argument/parameter. */
643634
bindingset[n]
644-
string parameter(int n) { result = parameterByStr(n.toString()) }
635+
bindingset[result]
636+
string parameter(int n) {
637+
exists(string s |
638+
result = parameterByStr(s) and
639+
n = s.toInt() and
640+
s = n.toString()
641+
)
642+
}
645643

646644
/** Gets the label representing the `n`th positional argument/parameter. */
647645
bindingset[n]

0 commit comments

Comments
 (0)