Skip to content

Commit aaff322

Browse files
committed
Ruby: prefer ...isInt(x) over x = ...getInt()
1 parent 45962f1 commit aaff322

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

ruby/ql/lib/codeql/ruby/frameworks/Array.qll

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ module Array {
237237
ElementReferenceRangeReadKnownSummary() {
238238
mc.getNumberOfArguments() = 2 and
239239
start = getKnownArrayElementContent(mc.getArgument(0)).getIndex() and
240-
exists(int length | length = mc.getArgument(1).getConstantValue().getInt() |
240+
exists(int length | mc.getArgument(1).getConstantValue().isInt(length) |
241241
end = (start + length - 1) and
242242
this = "[](" + start + ", " + length + ")"
243243
)
@@ -565,7 +565,7 @@ module Array {
565565

566566
DeleteAtKnownSummary() {
567567
this = "delete_at(" + i + ")" and
568-
i = mc.getArgument(0).getConstantValue().getInt() and
568+
mc.getArgument(0).getConstantValue().isInt(i) and
569569
i >= 0
570570
}
571571

@@ -589,7 +589,7 @@ module Array {
589589
private class DeleteAtUnknownSummary extends DeleteAtSummary {
590590
DeleteAtUnknownSummary() {
591591
this = "delete_at(index)" and
592-
not exists(int i | i = mc.getArgument(0).getConstantValue().getInt() and i >= 0)
592+
not exists(int i | mc.getArgument(0).getConstantValue().isInt(i) and i >= 0)
593593
}
594594

595595
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
@@ -735,7 +735,7 @@ module Array {
735735

736736
FetchKnownSummary() {
737737
this = "fetch(" + i + ")" and
738-
i = mc.getArgument(0).getConstantValue().getInt() and
738+
mc.getArgument(0).getConstantValue().isInt(i) and
739739
i >= 0
740740
}
741741

@@ -762,7 +762,7 @@ module Array {
762762
private class FetchUnknownSummary extends FetchSummary {
763763
FetchUnknownSummary() {
764764
this = "fetch(index)" and
765-
not exists(int i | i = mc.getArgument(0).getConstantValue().getInt() and i >= 0)
765+
not exists(int i | mc.getArgument(0).getConstantValue().isInt(i) and i >= 0)
766766
}
767767

768768
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
@@ -878,7 +878,7 @@ module Array {
878878

879879
InsertKnownSummary() {
880880
this = "insert(" + i + ")" and
881-
i = mc.getArgument(0).getConstantValue().getInt()
881+
mc.getArgument(0).getConstantValue().isInt(i)
882882
}
883883

884884
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
@@ -1215,7 +1215,7 @@ module Array {
12151215
private int c;
12161216

12171217
RotateKnownSummary() {
1218-
c = mc.getArgument(0).getConstantValue().getInt() and
1218+
mc.getArgument(0).getConstantValue().isInt(c) and
12191219
this = "rotate(" + c + ")"
12201220
or
12211221
not exists(mc.getArgument(0)) and c = 1 and this = "rotate"
@@ -1271,7 +1271,7 @@ module Array {
12711271
private int c;
12721272

12731273
RotateBangKnownSummary() {
1274-
c = mc.getArgument(0).getConstantValue().getInt() and
1274+
mc.getArgument(0).getConstantValue().isInt(c) and
12751275
this = "rotate!(" + c + ")"
12761276
or
12771277
not exists(mc.getArgument(0)) and c = 1 and this = "rotate!"
@@ -1364,7 +1364,7 @@ module Array {
13641364
private int n;
13651365

13661366
ShiftArgKnownSummary() {
1367-
n = mc.getArgument(0).getConstantValue().getInt() and
1367+
mc.getArgument(0).getConstantValue().isInt(n) and
13681368
this = "shift(" + n + ")"
13691369
}
13701370

@@ -1489,7 +1489,7 @@ module Array {
14891489
SliceBangRangeKnownSummary() {
14901490
mc.getNumberOfArguments() = 2 and
14911491
start = getKnownArrayElementContent(mc.getArgument(0)).getIndex() and
1492-
exists(int length | length = mc.getArgument(1).getConstantValue().getInt() |
1492+
exists(int length | mc.getArgument(1).getConstantValue().isInt(length) |
14931493
end = (start + length - 1) and
14941494
this = "slice!(" + start + ", " + length + ")"
14951495
)
@@ -1681,7 +1681,7 @@ module Array {
16811681
or
16821682
exists(ArrayIndex elementIndex, int argIndex |
16831683
argIndex in [0 .. mc.getNumberOfArguments() - 1] and
1684-
elementIndex = mc.getArgument(argIndex).getConstantValue().getInt()
1684+
mc.getArgument(argIndex).getConstantValue().isInt(elementIndex)
16851685
|
16861686
input = "ArrayElement[" + elementIndex + "] of Receiver" and
16871687
output = "ArrayElement[" + argIndex + "] of ReturnValue"
@@ -1698,7 +1698,7 @@ module Array {
16981698
ValuesAtUnknownSummary() {
16991699
this = "values_at(unknown)" and
17001700
exists(int i | i in [0 .. mc.getNumberOfArguments() - 1] |
1701-
not exists(int val | val = mc.getArgument(i).getConstantValue().getInt() and val >= 0)
1701+
not exists(int val | mc.getArgument(i).getConstantValue().isInt(val) and val >= 0)
17021702
)
17031703
}
17041704

@@ -1827,7 +1827,7 @@ module Enumerable {
18271827

18281828
DropKnownSummary() {
18291829
this = "drop(" + i + ")" and
1830-
i = mc.getArgument(0).getConstantValue().getInt()
1830+
mc.getArgument(0).getConstantValue().isInt(i)
18311831
}
18321832

18331833
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
@@ -1995,7 +1995,7 @@ module Enumerable {
19951995
private int n;
19961996

19971997
FirstArgKnownSummary() {
1998-
this = "first(" + n + ")" and n = mc.getArgument(0).getConstantValue().getInt()
1998+
this = "first(" + n + ")" and mc.getArgument(0).getConstantValue().isInt(n)
19991999
}
20002000

20012001
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {
@@ -2391,7 +2391,7 @@ module Enumerable {
23912391

23922392
TakeKnownSummary() {
23932393
this = "take(" + i + ")" and
2394-
i = mc.getArgument(0).getConstantValue().getInt()
2394+
mc.getArgument(0).getConstantValue().isInt(i)
23952395
}
23962396

23972397
override predicate propagatesFlowExt(string input, string output, boolean preservesValue) {

0 commit comments

Comments
 (0)