summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-05-17 16:33:07 +1000
committerDamien George <damien.p.george@gmail.com>2017-05-18 17:32:42 +1000
commiteb4c37f7a47f4afa630ffd754c579a8c4a81ad93 (patch)
tree1949c6c0add635390553b0afa827cb78abf4810e
parentd007351b3377f97316c4af2adcec164fb5e56dca (diff)
downloadmicropython-eb4c37f7a47f4afa630ffd754c579a8c4a81ad93.tar.gz
micropython-eb4c37f7a47f4afa630ffd754c579a8c4a81ad93.zip
py/sequence: Fix boundary errors when slicing with a negative step.
-rw-r--r--py/sequence.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/py/sequence.c b/py/sequence.c
index cd1a966179..32db640dc1 100644
--- a/py/sequence.c
+++ b/py/sequence.c
@@ -88,15 +88,22 @@ bool mp_seq_get_fast_slice_indexes(mp_uint_t len, mp_obj_t slice, mp_bound_slice
if (start < 0) {
start = len + start;
if (start < 0) {
- start = 0;
+ if (indexes->step < 0) {
+ start = -1;
+ } else {
+ start = 0;
+ }
}
} else if (indexes->step > 0 && (mp_uint_t)start > len) {
start = len;
- } else if (indexes->step < 0 && (mp_uint_t)start > len - 1) {
+ } else if (indexes->step < 0 && (mp_uint_t)start >= len) {
start = len - 1;
}
if (stop < 0) {
stop = len + stop;
+ if (stop < 0) {
+ stop = -1;
+ }
if (indexes->step < 0) {
stop += 1;
}