[Python-checkins] CVS: python/dist/src/Objects dictobject.c,2.89,2.90

Tim Peters tim_one@users.sourceforge.net
Sat, 19 May 2001 00:04:41 -0700


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

Modified Files:
	dictobject.c 
Log Message:
Bugfix candidate.
Two exceedingly unlikely errors in dictresize():
1. The loop for finding the new size had an off-by-one error at the
   end (could over-index the polys[] vector).
2. The polys[] vector ended with a 0, apparently intended as a sentinel
   value but never used as such; i.e., it was never checked, so 0 could
   have been used *as* a polynomial.
Neither bug could trigger unless a dict grew to 2**30 slots; since that
would consume at least 12GB of memory just to hold the dict pointers,
I'm betting it's not the cause of the bug Fred's tracking down <wink>.


Index: dictobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/dictobject.c,v
retrieving revision 2.89
retrieving revision 2.90
diff -C2 -r2.89 -r2.90
*** dictobject.c	2001/05/17 22:25:34	2.89
--- dictobject.c	2001/05/19 07:04:38	2.90
***************
*** 48,52 ****
  	536870912 + 5,
  	1073741824 + 83,
- 	0
  };
  
--- 48,51 ----
***************
*** 374,379 ****
  	register dictentry *ep;
  	register int i;
  	for (i = 0, newsize = MINSIZE; ; i++, newsize <<= 1) {
! 		if (i > sizeof(polys)/sizeof(polys[0])) {
  			/* Ran out of polynomials */
  			PyErr_NoMemory();
--- 373,380 ----
  	register dictentry *ep;
  	register int i;
+ 
+ 	assert(minused >= 0);
  	for (i = 0, newsize = MINSIZE; ; i++, newsize <<= 1) {
! 		if (i >= sizeof(polys)/sizeof(polys[0])) {
  			/* Ran out of polynomials */
  			PyErr_NoMemory();