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

M.-A. Lemburg mal@lemburg.com
Thu, 07 Feb 2002 12:38:16 +0100


"M.-A. Lemburg" wrote:
> 
> Update of /cvsroot/python/python/dist/src/Objects
> In directory usw-pr-cvs1:/tmp/cvs-serv8617/Objects
> 
> Modified Files:
>         unicodeobject.c
> Log Message:
> Fix to the UTF-8 encoder: it failed on 0-length input strings.
>
> ...
>
> Index: unicodeobject.c
> ===================================================================
> RCS file: /cvsroot/python/python/dist/src/Objects/unicodeobject.c,v
> retrieving revision 2.127
> retrieving revision 2.128
> diff -C2 -d -r2.127 -r2.128
> *** unicodeobject.c     6 Feb 2002 18:20:19 -0000       2.127
> --- unicodeobject.c     7 Feb 2002 11:33:49 -0000       2.128
> ***************
> ***************
> *** 1176,1184 ****
>       int i = 0;
> 
>       v = PyString_FromStringAndSize(NULL, cbAllocated + 4);
>       if (v == NULL)
>           return NULL;
> -     if (size == 0)
> -         return v;
> 
>       p = PyString_AS_STRING(v);
> --- 1183,1195 ----
>       int i = 0;
> 
> +     /* Short-cut for emtpy strings */
> +     if (size == 0)
> +       return PyString_FromStringAndSize(NULL, 0);
> +
> +     /* We allocate 4 more bytes to have room for at least one full
> +        UTF-8 sequence; saves a few cycles in the loop below */
>       v = PyString_FromStringAndSize(NULL, cbAllocated + 4);
>       if (v == NULL)
>           return NULL;
> 
>       p = PyString_AS_STRING(v);

This part of the patch should be considered a bug-fix candidate for
2.2.1. It fixes a problem introduced by yesterdays patch.

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Company & Consulting:                           http://www.egenix.com/
Python Software:                   http://www.egenix.com/files/python/