[Python-checkins] python/dist/src/Objects unicodeobject.c, 2.190.6.6, 2.190.6.7

jhylton at users.sourceforge.net jhylton at users.sourceforge.net
Tue Sep 16 23:22:30 EDT 2003


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

Modified Files:
      Tag: release23-maint
	unicodeobject.c 
Log Message:
Backport Tim's portability improvement and comments.


Index: unicodeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/unicodeobject.c,v
retrieving revision 2.190.6.6
retrieving revision 2.190.6.7
diff -C2 -d -r2.190.6.6 -r2.190.6.7
*** unicodeobject.c	16 Sep 2003 20:30:03 -0000	2.190.6.6
--- unicodeobject.c	17 Sep 2003 03:22:27 -0000	2.190.6.7
***************
*** 133,137 ****
      if (unicode == unicode_empty || 
  	(unicode->length == 1 && 
! 	 unicode->str[0] < 256U &&
  	 unicode_latin1[unicode->str[0]] == unicode)) {
          PyErr_SetString(PyExc_SystemError,
--- 133,142 ----
      if (unicode == unicode_empty || 
  	(unicode->length == 1 && 
!          /* MvL said unicode->str[] may be signed.  Python generally assumes
!           * an int contains at least 32 bits, and we don't use more than
!           * 32 bits even in a UCS4 build, so casting to unsigned int should
!           * be correct.
!           */
! 	 (unsigned int)unicode->str[0] < 256U &&
  	 unicode_latin1[unicode->str[0]] == unicode)) {
          PyErr_SetString(PyExc_SystemError,
***************
*** 212,215 ****
--- 217,227 ----
  	goto onError;
      }
+     /* Initialize the first element to guard against cases where
+      * the caller fails before initializing str -- unicode_resize()
+      * reads str[0], and the Keep-Alive optimization can keep memory
+      * allocated for str alive across a call to unicode_dealloc(unicode).
+      * We don't want unicode_resize to read uninitialized memory in
+      * that case.
+      */
      unicode->str[0] = 0;
      unicode->str[length] = 0;





More information about the Python-checkins mailing list