Commit a10311c4 authored by Michael W. Hudson's avatar Michael W. Hudson

Fix for problem reported by Neal Norwitz. Tighten up calculation of

slicelength.  Include his test case.
parent 722aaa61
...@@ -374,6 +374,8 @@ vereq(a[3::-2], [3,1]) ...@@ -374,6 +374,8 @@ vereq(a[3::-2], [3,1])
vereq(a[-100:100:], a) vereq(a[-100:100:], a)
vereq(a[100:-100:-1], a[::-1]) vereq(a[100:-100:-1], a[::-1])
vereq(a[-100L:100L:2L], [0,2,4]) vereq(a[-100L:100L:2L], [0,2,4])
vereq(a[1000:2000:2], [])
vereq(a[-1000:-2000:-2], [])
# deletion # deletion
del a[::2] del a[::2]
vereq(a, [1,3]) vereq(a, [1,3])
......
...@@ -152,12 +152,14 @@ PySlice_GetIndicesEx(PySliceObject *r, int length, ...@@ -152,12 +152,14 @@ PySlice_GetIndicesEx(PySliceObject *r, int length,
if (*stop > length) *stop = length; if (*stop > length) *stop = length;
} }
if (*step < 0) { if ((*stop - *start)*(*step) <= 0) {
*slicelength = 0;
}
else if (*step < 0) {
*slicelength = (*stop-*start+1)/(*step)+1; *slicelength = (*stop-*start+1)/(*step)+1;
} else { } else {
*slicelength = (*stop-*start-1)/(*step)+1; *slicelength = (*stop-*start-1)/(*step)+1;
} }
if (*slicelength < 0) *slicelength = 0;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment