summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-03-01 20:59:58 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-03-01 20:59:58 (GMT)
commit337986740f26ade866dbe79e35188f72caa8fe8d (patch)
tree0dfe877dfcfe031ede9b96798c8f3645cb4a25e5 /Objects
parent6c9aa8f2bf46e28de74ce11d85bcd448c0d0d529 (diff)
downloadcpython-337986740f26ade866dbe79e35188f72caa8fe8d.zip
cpython-337986740f26ade866dbe79e35188f72caa8fe8d.tar.gz
cpython-337986740f26ade866dbe79e35188f72caa8fe8d.tar.bz2
Issue #26464: Fix unicode_fast_translate() again
Initialize i variable if the string is non-ASCII.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/unicodeobject.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index a1ee776..adc4615 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -8582,10 +8582,6 @@ unicode_fast_translate(PyObject *input, PyObject *mapping,
Py_UCS1 *in, *end, *out;
int res = 0;
- if (PyUnicode_READY(input) == -1)
- return -1;
- if (!PyUnicode_IS_ASCII(input))
- return 0;
len = PyUnicode_GET_LENGTH(input);
memset(ascii_table, 0xff, 128);
@@ -8668,13 +8664,20 @@ _PyUnicode_TranslateCharmap(PyObject *input,
ignore = (errors != NULL && strcmp(errors, "ignore") == 0);
- res = unicode_fast_translate(input, mapping, &writer, ignore, &i);
- if (res < 0) {
- _PyUnicodeWriter_Dealloc(&writer);
+ if (PyUnicode_READY(input) == -1)
return NULL;
+ if (PyUnicode_IS_ASCII(input)) {
+ res = unicode_fast_translate(input, mapping, &writer, ignore, &i);
+ if (res < 0) {
+ _PyUnicodeWriter_Dealloc(&writer);
+ return NULL;
+ }
+ if (res == 1)
+ return _PyUnicodeWriter_Finish(&writer);
+ }
+ else {
+ i = 0;
}
- if (res == 1)
- return _PyUnicodeWriter_Finish(&writer);
while (i<size) {
/* try to encode it */