diff Objects/unicodeobject.c @ 64662:c35b42a8da3f

detect non-ascii characters much earlier (plugs ref leak)
author Benjamin Peterson <benjamin@python.org>
date Sun, 12 Sep 2010 03:40:54 +0000
parents 1cfad55de5bd
children 852bb052156a
line wrap: on
line diff
--- a/Objects/unicodeobject.c	Sat Sep 11 22:35:24 2010 +0000
+++ b/Objects/unicodeobject.c	Sun Sep 12 03:40:54 2010 +0000
@@ -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;
     }