Skip to content

Commit

Permalink
Merge pull request #16 from jakirkham/fix_ref_bounds
Browse files Browse the repository at this point in the history
Fix out-of-bounds handling in reformat_slice
  • Loading branch information
jakirkham committed Dec 2, 2016
2 parents 21ab634 + 56323ec commit a78bebe
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions kenjutsu/kenjutsu.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,19 @@ def reformat_slice(a_slice, a_length=None):
if step > 0:
if (start > a_length) or (stop < -a_length):
start = stop = 0
elif start < -a_length:
start = 0
elif stop > a_length:
stop = a_length
else:
if start < -a_length:
start = 0
if stop > a_length:
stop = a_length
elif step < 0:
if (start < -a_length) or (stop >= (a_length - 1)):
start = stop = 0
elif start >= a_length:
start = a_length - 1
elif stop < -a_length:
stop = None
else:
if start >= a_length:
start = a_length - 1
if stop < -a_length:
stop = None

# Catch some known empty slices.
if (step > 0) and (stop == 0):
Expand Down

0 comments on commit a78bebe

Please sign in to comment.