Skip to content

Commit 2e850bc

Browse files
committed
Fix out-of-bound index access
1 parent f8a74da commit 2e850bc

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

lib/debug/variable_inspector.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ class VariableInspector
77
def indexed_members_of(obj, start:, count:)
88
return [] if start > (obj.length - 1)
99

10-
(start...(start + count)).map do |i|
10+
capped_count = [count, obj.length - start].min
11+
12+
(start...(start + capped_count)).map do |i|
1113
Variable.new(name: i.to_s, value: obj[i])
1214
end
1315
end

test/protocol/hover_raw_dap_test.rb

+9-17
Original file line numberDiff line numberDiff line change
@@ -619,14 +619,6 @@ def test_hover_works_correctly
619619
variablesReference: 30,
620620
namedVariables: /\d+/
621621
},
622-
{
623-
# This is an extra entry caused by an out-of-bounds index access in server_dap.rb
624-
name: "9",
625-
value: nil,
626-
type: NilClass,
627-
variablesReference: 31,
628-
namedVariables: /\d+/
629-
}
630622
]
631623
}
632624
},
@@ -649,7 +641,7 @@ def test_hover_works_correctly
649641
message: "Success",
650642
body: {
651643
type: "Integer",
652-
variablesReference: 32,
644+
variablesReference: 31,
653645
namedVariables: /\d+/,
654646
result: "3"
655647
}
@@ -658,7 +650,7 @@ def test_hover_works_correctly
658650
seq: 23,
659651
command: "variables",
660652
arguments: {
661-
variablesReference: 32
653+
variablesReference: 31
662654
},
663655
type: "request"
664656
},
@@ -675,7 +667,7 @@ def test_hover_works_correctly
675667
name: "#class",
676668
value: "Integer",
677669
type: "Class",
678-
variablesReference: 33,
670+
variablesReference: 32,
679671
namedVariables: /\d+/
680672
}
681673
]
@@ -700,7 +692,7 @@ def test_hover_works_correctly
700692
message: "Success",
701693
body: {
702694
type: "Integer",
703-
variablesReference: 34,
695+
variablesReference: 33,
704696
namedVariables: /\d+/,
705697
result: "2"
706698
}
@@ -709,7 +701,7 @@ def test_hover_works_correctly
709701
seq: 25,
710702
command: "variables",
711703
arguments: {
712-
variablesReference: 34
704+
variablesReference: 33
713705
},
714706
type: "request"
715707
},
@@ -726,7 +718,7 @@ def test_hover_works_correctly
726718
name: "#class",
727719
value: "Integer",
728720
type: "Class",
729-
variablesReference: 35,
721+
variablesReference: 34,
730722
namedVariables: /\d+/
731723
}
732724
]
@@ -751,7 +743,7 @@ def test_hover_works_correctly
751743
message: "Success",
752744
body: {
753745
type: "Integer",
754-
variablesReference: 36,
746+
variablesReference: 35,
755747
namedVariables: /\d+/,
756748
result: "1"
757749
}
@@ -760,7 +752,7 @@ def test_hover_works_correctly
760752
seq: 27,
761753
command: "variables",
762754
arguments: {
763-
variablesReference: 36
755+
variablesReference: 35
764756
},
765757
type: "request"
766758
},
@@ -777,7 +769,7 @@ def test_hover_works_correctly
777769
name: "#class",
778770
value: "Integer",
779771
type: "Class",
780-
variablesReference: 37,
772+
variablesReference: 36,
781773
namedVariables: /\d+/
782774
}
783775
]

0 commit comments

Comments
 (0)