[Python-checkins] python/dist/src/Modules binascii.c,2.39,2.40

bwarsaw at users.sourceforge.net bwarsaw at users.sourceforge.net
Mon May 10 22:05:17 EDT 2004


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31678

Modified Files:
	binascii.c 
Log Message:
In order to fix SF bug # 824977, we replace calloc()/free() calls in
binascii_a2b_qp() and binascii_b2a_qp() with calls to PyMem_Malloc() and
PyMem_Free().  These won't return NULL unless the allocations actually fail,
so it won't trigger a bogus memory error on some platforms <cough>AIX</cough>
when passed a length of zero.


Index: binascii.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/binascii.c,v
retrieving revision 2.39
retrieving revision 2.40
diff -C2 -d -r2.39 -r2.40
*** binascii.c	17 Mar 2003 11:24:29 -0000	2.39
--- binascii.c	11 May 2004 02:05:11 -0000	2.40
***************
*** 1037,1047 ****
  		return NULL;
  
! 	/* We allocate the output same size as input, this is overkill */
! 	odata = (unsigned char *) calloc(1, datalen);
! 
  	if (odata == NULL) {
  		PyErr_NoMemory();
  		return NULL;
  	}
  
  	in = out = 0;
--- 1037,1050 ----
  		return NULL;
  
! 	/* We allocate the output same size as input, this is overkill.
! 	 * The previous implementation used calloc() so we'll zero out the
! 	 * memory here too, since PyMem_Malloc() does not guarantee that.
! 	 */
! 	odata = (unsigned char *) PyMem_Malloc(datalen);
  	if (odata == NULL) {
  		PyErr_NoMemory();
  		return NULL;
  	}
+ 	memset(odata, datalen, 0);
  
  	in = out = 0;
***************
*** 1091,1098 ****
  	}
  	if ((rv = PyString_FromStringAndSize((char *)odata, out)) == NULL) {
! 		free (odata);
  		return NULL;
  	}
! 	free (odata);
  	return rv;
  }
--- 1094,1101 ----
  	}
  	if ((rv = PyString_FromStringAndSize((char *)odata, out)) == NULL) {
! 		PyMem_Free(odata);
  		return NULL;
  	}
! 	PyMem_Free(odata);
  	return rv;
  }
***************
*** 1208,1217 ****
  	}
  
! 	odata = (unsigned char *) calloc(1, odatalen);
! 
  	if (odata == NULL) {
  		PyErr_NoMemory();
  		return NULL;
  	}
  
  	in = out = linelen = 0;
--- 1211,1224 ----
  	}
  
! 	/* We allocate the output same size as input, this is overkill.
! 	 * The previous implementation used calloc() so we'll zero out the
! 	 * memory here too, since PyMem_Malloc() does not guarantee that.
! 	 */
! 	odata = (unsigned char *) PyMem_Malloc(odatalen);
  	if (odata == NULL) {
  		PyErr_NoMemory();
  		return NULL;
  	}
+ 	memset(odata, odatalen, 0);
  
  	in = out = linelen = 0;
***************
*** 1282,1289 ****
  	}
  	if ((rv = PyString_FromStringAndSize((char *)odata, out)) == NULL) {
! 		free (odata);
  		return NULL;
  	}
! 	free (odata);
  	return rv;
  }
--- 1289,1296 ----
  	}
  	if ((rv = PyString_FromStringAndSize((char *)odata, out)) == NULL) {
! 		PyMem_Free(odata);
  		return NULL;
  	}
! 	PyMem_Free(odata);
  	return rv;
  }




More information about the Python-checkins mailing list