[Python-checkins] python/dist/src/Python errors.c,2.73,2.74

mhammond@users.sourceforge.net mhammond@users.sourceforge.net
2002年10月03日 17:13:05 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv15788
Modified Files:
	errors.c 
Log Message:
Fix [ 616716 ] Bug in PyErr_SetExcFromWindows
Ensure that even if FormatMessage fails we (a) don't crash, and (b) provide something useful.
Bugfix candidate.
Index: errors.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/errors.c,v
retrieving revision 2.73
retrieving revision 2.74
diff -C2 -d -r2.73 -r2.74
*** errors.c	4 Oct 2002 00:09:38 -0000	2.73
--- errors.c	4 Oct 2002 00:13:02 -0000	2.74
***************
*** 270,273 ****
--- 270,274 ----
 #ifdef MS_WINDOWS
 	char *s_buf = NULL;
+ 	char s_small_buf[28]; /* Room for "Windows Error 0xFFFFFFFF" */
 #endif
 #ifdef EINTR
***************
*** 307,314 ****
 				0,	/* size not used */
 				NULL);	/* no args */
! 			s = s_buf;
! 			/* remove trailing cr/lf and dots */
! 			while (len > 0 && (s[len-1] <= ' ' || s[len-1] == '.'))
! 				s[--len] = '0円';
 		}
 	}
--- 308,323 ----
 				0,	/* size not used */
 				NULL);	/* no args */
! 			if (len==0) {
! 				/* Only ever seen this in out-of-mem 
! 				 situations */
! 				sprintf(s_small_buf, "Windows Error 0x%X", i);
! 				s = s_small_buf;
! 				s_buf = NULL;
! 			} else {
! 				s = s_buf;
! 				/* remove trailing cr/lf and dots */
! 				while (len > 0 && (s[len-1] <= ' ' || s[len-1] == '.'))
! 					s[--len] = '0円';
! 			}
 		}
 	}
***************
*** 367,370 ****
--- 376,381 ----
 	int len;
 	char *s;
+ 	char *s_buf = NULL; /* Free via LocalFree */
+ 	char s_small_buf[28]; /* Room for "Windows Error 0xFFFFFFFF" */
 	PyObject *v;
 	DWORD err = (DWORD)ierr;
***************
*** 379,388 ****
 		MAKELANGID(LANG_NEUTRAL,
 		SUBLANG_DEFAULT), /* Default language */
! 		(LPTSTR) &s,
 		0,	/* size not used */
 		NULL);	/* no args */
! 	/* remove trailing cr/lf and dots */
! 	while (len > 0 && (s[len-1] <= ' ' || s[len-1] == '.'))
! 		s[--len] = '0円';
 	if (filenameObject != NULL)
 		v = Py_BuildValue("(isO)", err, s, filenameObject);
--- 390,407 ----
 		MAKELANGID(LANG_NEUTRAL,
 		SUBLANG_DEFAULT), /* Default language */
! 		(LPTSTR) &s_buf,
 		0,	/* size not used */
 		NULL);	/* no args */
! 	if (len==0) {
! 		/* Only seen this in out of mem situations */
! 		sprintf(s_small_buf, "Windows Error 0x%X", err);
! 		s = s_small_buf;
! 		s_buf = NULL;
! 	} else {
! 		s = s_buf;
! 		/* remove trailing cr/lf and dots */
! 		while (len > 0 && (s[len-1] <= ' ' || s[len-1] == '.'))
! 			s[--len] = '0円';
! 	}
 	if (filenameObject != NULL)
 		v = Py_BuildValue("(isO)", err, s, filenameObject);
***************
*** 393,397 ****
 		Py_DECREF(v);
 	}
! 	LocalFree(s);
 	return NULL;
 }
--- 412,416 ----
 		Py_DECREF(v);
 	}
! 	LocalFree(s_buf);
 	return NULL;
 }

AltStyle によって変換されたページ (->オリジナル) /