detect non-ascii characters much earlier (plugs ref leak)
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index c010b1b..3b0a66a 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -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;
}