[Python-checkins] CVS: python/dist/src/Objects stringobject.c,2.114,2.115

Tim Peters tim_one@users.sourceforge.net
Wed, 09 May 2001 17:32:59 -0700


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

Modified Files:
	stringobject.c 
Log Message:
Heh.  I need a break.  After this:  stropmodule & stringobject were more
out of synch than I realized, and I managed to break replace's "count"
argument when it was 0.  All is well again.  Maybe.
Bugfix candidate.


Index: stringobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/stringobject.c,v
retrieving revision 2.114
retrieving revision 2.115
diff -C2 -r2.114 -r2.115
*** stringobject.c	2001/05/10 00:05:33	2.114
--- stringobject.c	2001/05/10 00:32:57	2.115
***************
*** 1558,1563 ****
  	/* find length of output string */
  	nfound = mymemcnt(str, len, pat, pat_len);
! 	if (count > 0)
! 		nfound = nfound > count ? count : nfound;
  	if (nfound == 0)
  		goto return_same;
--- 1558,1565 ----
  	/* find length of output string */
  	nfound = mymemcnt(str, len, pat, pat_len);
! 	if (count < 0)
! 		count = INT_MAX;
! 	else if (nfound > count)
! 		nfound = count;
  	if (nfound == 0)
  		goto return_same;
***************
*** 1567,1571 ****
  		/* Have to allocate something for the caller to free(). */
  		out_s = (char *)PyMem_MALLOC(1);
! 		if (out_s = NULL)
  			return NULL;
  		out_s[0] = '\0';
--- 1569,1573 ----
  		/* Have to allocate something for the caller to free(). */
  		out_s = (char *)PyMem_MALLOC(1);
! 		if (out_s == NULL)
  			return NULL;
  		out_s[0] = '\0';
***************
*** 1578,1582 ****
  		out_s = new_s;
  
! 		while (len > 0) {
  			/* find index of next instance of pattern */
  			offset = mymemfind(str, len, pat, pat_len);
--- 1580,1584 ----
  		out_s = new_s;
  
! 		for (; count > 0 && len > 0; --count) {
  			/* find index of next instance of pattern */
  			offset = mymemfind(str, len, pat, pat_len);
***************
*** 1593,1600 ****
  			memcpy(new_s, sub, sub_len);
  			new_s += sub_len;
- 
- 			/* note count==0 is effectively infinity */
- 			if (--count == 0)
- 				break;
  		}
  		/* copy any remaining values into output string */
--- 1595,1598 ----