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

Skip to content

Commit d21b58c

Browse files
committed
Issue #17223: Fix PyUnicode_FromUnicode() for string of 1 character outside
the range U+0000-U+10ffff.
1 parent f8cf59e commit d21b58c

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 3.3.1?
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #17223: Fix PyUnicode_FromUnicode() for string of 1 character outside
16+
the range U+0000-U+10ffff.
17+
1518
- Issue #17275: Corrected class name in init error messages of the C version of
1619
BufferedWriter and BufferedRandom.
1720

Objects/unicodeobject.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ static int unicode_modifiable(PyObject *unicode);
249249

250250

251251
static PyObject *
252-
_PyUnicode_FromUCS1(const unsigned char *s, Py_ssize_t size);
252+
_PyUnicode_FromUCS1(const Py_UCS1 *s, Py_ssize_t size);
253253
static PyObject *
254254
_PyUnicode_FromUCS2(const Py_UCS2 *s, Py_ssize_t size);
255255
static PyObject *
@@ -442,7 +442,7 @@ unicode_result_wchar(PyObject *unicode)
442442

443443
if (len == 1) {
444444
wchar_t ch = _PyUnicode_WSTR(unicode)[0];
445-
if (ch < 256) {
445+
if ((Py_UCS4)ch < 256) {
446446
PyObject *latin1_char = get_latin1_char((unsigned char)ch);
447447
Py_DECREF(unicode);
448448
return latin1_char;
@@ -1761,7 +1761,7 @@ PyUnicode_FromUnicode(const Py_UNICODE *u, Py_ssize_t size)
17611761

17621762
/* Single character Unicode objects in the Latin-1 range are
17631763
shared when using this constructor */
1764-
if (size == 1 && *u < 256)
1764+
if (size == 1 && (Py_UCS4)*u < 256)
17651765
return get_latin1_char((unsigned char)*u);
17661766

17671767
/* If not empty and not single character, copy the Unicode data
@@ -1869,7 +1869,7 @@ _PyUnicode_FromASCII(const char *buffer, Py_ssize_t size)
18691869
PyObject *unicode;
18701870
if (size == 1) {
18711871
#ifdef Py_DEBUG
1872-
assert(s[0] < 128);
1872+
assert((unsigned char)s[0] < 128);
18731873
#endif
18741874
return get_latin1_char(s[0]);
18751875
}
@@ -1911,7 +1911,7 @@ align_maxchar(Py_UCS4 maxchar)
19111911
}
19121912

19131913
static PyObject*
1914-
_PyUnicode_FromUCS1(const unsigned char* u, Py_ssize_t size)
1914+
_PyUnicode_FromUCS1(const Py_UCS1* u, Py_ssize_t size)
19151915
{
19161916
PyObject *res;
19171917
unsigned char max_char;
@@ -2974,8 +2974,8 @@ PyUnicode_FromOrdinal(int ordinal)
29742974
return NULL;
29752975
}
29762976

2977-
if (ordinal < 256)
2978-
return get_latin1_char(ordinal);
2977+
if ((Py_UCS4)ordinal < 256)
2978+
return get_latin1_char((unsigned char)ordinal);
29792979

29802980
v = PyUnicode_New(1, ordinal);
29812981
if (v == NULL)

0 commit comments

Comments
 (0)