Skip to content

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

Lines changed: 9 additions & 2 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy