[Python-checkins] CVS: python/dist/src/Objects unicodeobject.c,2.124.6.5,2.124.6.6

Michael Hudson mwh@users.sourceforge.net
Mon, 18 Mar 2002 04:47:54 -0800


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

Modified Files:
      Tag: release22-maint
	unicodeobject.c 
Log Message:
Martin's fix for 

[ 529104 ] broken error handling in unicode-escape

I presume this will need to be fixed on the trunk, too.

Later.



Index: unicodeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/unicodeobject.c,v
retrieving revision 2.124.6.5
retrieving revision 2.124.6.6
diff -C2 -d -r2.124.6.5 -r2.124.6.6
*** unicodeobject.c	18 Mar 2002 12:43:33 -0000	2.124.6.5
--- unicodeobject.c	18 Mar 2002 12:47:52 -0000	2.124.6.6
***************
*** 1508,1513 ****
  
  static
! int unicodeescape_decoding_error(const char **source,
!                                  Py_UNICODE *x,
                                   const char *errors,
                                   const char *details) 
--- 1508,1512 ----
  
  static
! int unicodeescape_decoding_error(Py_UNICODE **x,
                                   const char *errors,
                                   const char *details) 
***************
*** 1524,1528 ****
      }
      else if (strcmp(errors,"replace") == 0) {
!         *x = Py_UNICODE_REPLACEMENT_CHARACTER;
          return 0;
      }
--- 1523,1528 ----
      }
      else if (strcmp(errors,"replace") == 0) {
!         **x = Py_UNICODE_REPLACEMENT_CHARACTER;
! 	(*x)++;
          return 0;
      }
***************
*** 1622,1628 ****
                  c = (unsigned char) s[i];
                  if (!isxdigit(c)) {
!                     if (unicodeescape_decoding_error(&s, &x, errors, message))
                          goto onError;
!                     chr = x;
                      i++;
                      break;
--- 1622,1628 ----
                  c = (unsigned char) s[i];
                  if (!isxdigit(c)) {
!                     if (unicodeescape_decoding_error(&p, errors, message))
                          goto onError;
!                     chr = 0xffffffff;
                      i++;
                      break;
***************
*** 1637,1640 ****
--- 1637,1644 ----
              }
              s += i;
+ 	    if (chr == 0xffffffff)
+ 		    /* _decoding_error will have already written into the
+ 		       target buffer. */
+ 		    break;
          store:
              /* when we get here, chr is a 32-bit unicode character */
***************
*** 1654,1662 ****
              } else {
                  if (unicodeescape_decoding_error(
!                     &s, &x, errors,
                      "illegal Unicode character")
                      )
                      goto onError;
-                 *p++ = x; /* store replacement character */
              }
              break;
--- 1658,1665 ----
              } else {
                  if (unicodeescape_decoding_error(
!                     &p, errors,
                      "illegal Unicode character")
                      )
                      goto onError;
              }
              break;
***************
*** 1693,1704 ****
                  }
              }
!             if (unicodeescape_decoding_error(&s, &x, errors, message))
                  goto onError;
-             *p++ = x;
              break;
  
          default:
!             *p++ = '\\';
!             *p++ = (unsigned char)s[-1];
              break;
          }
--- 1696,1712 ----
                  }
              }
!             if (unicodeescape_decoding_error(&p, errors, message))
                  goto onError;
              break;
  
          default:
! 	    if (s > end) {
! 		if (unicodeescape_decoding_error(&p, errors, "\\ at end of string"))
! 		    goto onError;
! 	    }
! 	    else {
! 		*p++ = '\\';
! 		*p++ = (unsigned char)s[-1];
! 	    }
              break;
          }
***************
*** 1903,1907 ****
      while (s < end) {
  	unsigned char c;
! 	Py_UNICODE x;
  	int i;
  
--- 1911,1915 ----
      while (s < end) {
  	unsigned char c;
! 	Py_UCS4 x;
  	int i;
  
***************
*** 1932,1938 ****
  	    c = (unsigned char)s[i];
  	    if (!isxdigit(c)) {
! 		if (unicodeescape_decoding_error(&s, &x, errors,
  						 "truncated \\uXXXX"))
  		    goto onError;
  		i++;
  		break;
--- 1940,1947 ----
  	    c = (unsigned char)s[i];
  	    if (!isxdigit(c)) {
! 		if (unicodeescape_decoding_error(&p, errors,
  						 "truncated \\uXXXX"))
  		    goto onError;
+ 		x = 0xffffffff;
  		i++;
  		break;
***************
*** 1947,1951 ****
  	}
  	s += i;
! 	*p++ = x;
      }
      if (_PyUnicode_Resize(&v, (int)(p - buf)))
--- 1956,1961 ----
  	}
  	s += i;
! 	if (x != 0xffffffff)
! 		*p++ = x;
      }
      if (_PyUnicode_Resize(&v, (int)(p - buf)))