Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 53b33e7

Browse files
author
Victor Stinner
committed
UnicodeTranslateError uses the new Unicode API
The index is a character index, not a index in a Py_UNICODE* string.
1 parent a1c03b0 commit 53b33e7

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

Objects/exceptions.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,8 +1751,8 @@ UnicodeTranslateError_str(PyObject *self)
17511751
if (reason_str == NULL)
17521752
goto done;
17531753

1754-
if (uself->start < PyUnicode_GET_SIZE(uself->object) && uself->end == uself->start+1) {
1755-
int badchar = (int)PyUnicode_AS_UNICODE(uself->object)[uself->start];
1754+
if (uself->start < PyUnicode_GET_LENGTH(uself->object) && uself->end == uself->start+1) {
1755+
Py_UCS4 badchar = PyUnicode_ReadChar(uself->object, uself->start);
17561756
const char *fmt;
17571757
if (badchar <= 0xff)
17581758
fmt = "can't translate character '\\x%02x' in position %zd: %U";
@@ -1762,7 +1762,7 @@ UnicodeTranslateError_str(PyObject *self)
17621762
fmt = "can't translate character '\\U%08x' in position %zd: %U";
17631763
result = PyUnicode_FromFormat(
17641764
fmt,
1765-
badchar,
1765+
(int)badchar,
17661766
uself->start,
17671767
reason_str
17681768
);

0 commit comments

Comments
 (0)