summaryrefslogtreecommitdiffstats
path: root/Objects/sliceobject.c
diff options
context:
space:
mode:
authorMichael W. Hudson <mwh@python.net>2002-06-11 13:38:42 (GMT)
committerMichael W. Hudson <mwh@python.net>2002-06-11 13:38:42 (GMT)
commit589dc93620656faf80713b50b50d957664cea287 (patch)
tree9d3dcd7814ba7fcc82b26ed7b8dac942899cfa85 /Objects/sliceobject.c
parent75a20b19ef6925a5e6df55f4a738961127c25659 (diff)
downloadcpython-589dc93620656faf80713b50b50d957664cea287.zip
cpython-589dc93620656faf80713b50b50d957664cea287.tar.gz
cpython-589dc93620656faf80713b50b50d957664cea287.tar.bz2
Fix for problem reported by Neal Norwitz. Tighten up calculation of
slicelength. Include his test case.
Diffstat (limited to 'Objects/sliceobject.c')
-rw-r--r--Objects/sliceobject.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/Objects/sliceobject.c b/Objects/sliceobject.c
index 7499d31..9a268b7 100644
--- a/Objects/sliceobject.c
+++ b/Objects/sliceobject.c
@@ -151,13 +151,15 @@ PySlice_GetIndicesEx(PySliceObject *r, int length,
if (*stop < 0) *stop = -1;
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;
} else {
*slicelength = (*stop-*start-1)/(*step)+1;
}
- if (*slicelength < 0) *slicelength = 0;
return 0;
}