[Python-checkins] r84726 - python/branches/py3k/Objects/unicodeobject.c

benjamin.peterson python-checkins at python.org
Sun Sep 12 05:40:54 CEST 2010


Author: benjamin.peterson
Date: Sun Sep 12 05:40:54 2010
New Revision: 84726

Log:
detect non-ascii characters much earlier (plugs ref leak)

Modified:
   python/branches/py3k/Objects/unicodeobject.c

Modified: python/branches/py3k/Objects/unicodeobject.c
==============================================================================
--- python/branches/py3k/Objects/unicodeobject.c	(original)
+++ python/branches/py3k/Objects/unicodeobject.c	Sun Sep 12 05:40:54 2010
@@ -764,6 +764,13 @@
              if (*f == 's')
                  ++callcount;
          }
+         else if (128 <= (unsigned char)*f) {
+             PyErr_Format(PyExc_ValueError,
+                "PyUnicode_FromFormatV() expects an ASCII-encoded format "
+                "string, got a non-ascii byte: 0x%02x",
+                (unsigned char)*f);
+             return NULL;
+         }
     }
     /* step 2: allocate memory for the results of
      * PyObject_Str()/PyObject_Repr()/PyUnicode_DecodeUTF8() calls */
@@ -1103,13 +1110,6 @@
                 goto end;
             }
         }
-        else if (128 <= (unsigned char)*f) {
-            PyErr_Format(PyExc_ValueError,
-                "PyUnicode_FromFormatV() expects an ASCII-encoded format "
-                "string, got a non-ascii byte: 0x%02x",
-                (unsigned char)*f);
-            goto fail;
-        }
         else
             *s++ = *f;
     }


More information about the Python-checkins mailing list