[Python-checkins] python/dist/src/Objects sliceobject.c,2.13,2.14

mwh@users.sourceforge.net mwh@users.sourceforge.net
Tue, 11 Jun 2002 06:38:44 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv11746/Objects

Modified Files:
	sliceobject.c 
Log Message:
Fix for problem reported by Neal Norwitz.  Tighten up calculation of
slicelength.  Include his test case.


Index: sliceobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/sliceobject.c,v
retrieving revision 2.13
retrieving revision 2.14
diff -C2 -d -r2.13 -r2.14
*** sliceobject.c	11 Jun 2002 10:55:11 -0000	2.13
--- sliceobject.c	11 Jun 2002 13:38:42 -0000	2.14
***************
*** 152,162 ****
  		if (*stop > length) *stop = length;
  	}
! 
! 	if (*step < 0) {
  		*slicelength = (*stop-*start+1)/(*step)+1;
  	} else {
  		*slicelength = (*stop-*start-1)/(*step)+1;
  	}
- 	if (*slicelength < 0) *slicelength = 0;
  
  	return 0;
--- 152,164 ----
  		if (*stop > length) *stop = length;
  	}
! 	
! 	if ((*stop - *start)*(*step) <= 0) {
! 		*slicelength = 0;
! 	}
! 	else if (*step < 0) {
  		*slicelength = (*stop-*start+1)/(*step)+1;
  	} else {
  		*slicelength = (*stop-*start-1)/(*step)+1;
  	}
  
  	return 0;