Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit eb4c37f

Browse files
committed
py/sequence: Fix boundary errors when slicing with a negative step.
1 parent d007351 commit eb4c37f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

py/sequence.c

+9-2
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,22 @@ bool mp_seq_get_fast_slice_indexes(mp_uint_t len, mp_obj_t slice, mp_bound_slice
8888
if (start < 0) {
8989
start = len + start;
9090
if (start < 0) {
91-
start = 0;
91+
if (indexes->step < 0) {
92+
start = -1;
93+
} else {
94+
start = 0;
95+
}
9296
}
9397
} else if (indexes->step > 0 && (mp_uint_t)start > len) {
9498
start = len;
95-
} else if (indexes->step < 0 && (mp_uint_t)start > len - 1) {
99+
} else if (indexes->step < 0 && (mp_uint_t)start >= len) {
96100
start = len - 1;
97101
}
98102
if (stop < 0) {
99103
stop = len + stop;
104+
if (stop < 0) {
105+
stop = -1;
106+
}
100107
if (indexes->step < 0) {
101108
stop += 1;
102109
}

0 commit comments

Comments
 (0)