[Python-checkins] CVS: python/dist/src/Python sysmodule.c,2.96,2.97

Tim Peters tim_one@users.sourceforge.net
Sun, 02 Dec 2001 00:29:18 -0800


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

Modified Files:
	sysmodule.c 
Log Message:
mywrite():  The test for trouble in PyOS_vsnprintf was wrong on both
ends.  Also, when there is trouble, ensure the buffer has a traiing
0 byte.


Index: sysmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/sysmodule.c,v
retrieving revision 2.96
retrieving revision 2.97
diff -C2 -d -r2.96 -r2.97
*** sysmodule.c	2001/11/28 21:44:53	2.96
--- sysmodule.c	2001/12/02 08:29:16	2.97
***************
*** 1024,1034 ****
  	else {
  		char buffer[1001];
! 		int written = PyOS_vsnprintf(buffer, sizeof(buffer), 
! 					     format, va);
  		if (PyFile_WriteString(buffer, file) != 0) {
  			PyErr_Clear();
  			fputs(buffer, fp);
  		}
! 		if (written == -1 || written > sizeof(buffer)) {
  			const char *truncated = "... truncated";
  			if (PyFile_WriteString(truncated, file) != 0) {
--- 1024,1041 ----
  	else {
  		char buffer[1001];
! 		const int written = PyOS_vsnprintf(buffer, sizeof(buffer),
! 						   format, va);
! 		const int trouble = written < 0 || written >= sizeof(buffer);
! 		if (trouble) {
! 			/* Ensure there's a trailing null byte -- MS
! 			   vsnprintf fills the buffer to the very end
! 			   if it's not big enough. */
! 			buffer[sizeof(buffer) - 1] = '\0';
! 		}
  		if (PyFile_WriteString(buffer, file) != 0) {
  			PyErr_Clear();
  			fputs(buffer, fp);
  		}
! 		if (trouble) {
  			const char *truncated = "... truncated";
  			if (PyFile_WriteString(truncated, file) != 0) {