Skip to content

Commit 6216ac9

Browse files
committed
fix(vm): Don't try to cast subscript index before checking its range
1 parent dd75694 commit 6216ac9

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/vm.zig

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,9 +2568,7 @@ pub const VM = struct {
25682568
};
25692569
}
25702570

2571-
const list_index: usize = @intCast(index);
2572-
2573-
if (checked_or_leave != 1 and list_index >= list.items.items.len) {
2571+
if (checked_or_leave != 1 and index >= list.items.items.len) {
25742572
self.throw(
25752573
Error.OutOfBound,
25762574
(self.gc.copyString("Out of bound list access.") catch {
@@ -2592,10 +2590,10 @@ pub const VM = struct {
25922590
return;
25932591
}
25942592

2595-
const list_item = if (list_index >= list.items.items.len or list_index < 0)
2593+
const list_item = if (index >= list.items.items.len or index < 0)
25962594
Value.Null
25972595
else
2598-
list.items.items[list_index];
2596+
list.items.items[@intCast(index)];
25992597

26002598
// Pop list and index
26012599
if (checked_or_leave != 2) {

0 commit comments

Comments
 (0)