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

Skip to content

Commit 063e0cb

Browse files
committed
Fix to bug #393 (UTF16 codec didn't like empty strings) and
corrected some usage of 'unsigned long' where Py_UNICODE should have been used.
1 parent 295b1bb commit 063e0cb

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

Objects/unicodeobject.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -953,14 +953,13 @@ PyObject *PyUnicode_EncodeUTF16(const Py_UNICODE *s,
953953
sizeof(Py_UNICODE) * (size + (byteorder == 0)));
954954
if (v == NULL)
955955
return NULL;
956-
if (size == 0)
957-
goto done;
958956

959957
q = PyString_AS_STRING(v);
960958
p = (Py_UNICODE *)q;
961-
962959
if (byteorder == 0)
963960
*p++ = 0xFEFF;
961+
if (size == 0)
962+
goto done;
964963
if (byteorder == 0 ||
965964
#ifdef BYTEORDER_IS_LITTLE_ENDIAN
966965
byteorder == -1
@@ -994,7 +993,7 @@ PyObject *PyUnicode_AsUTF16String(PyObject *unicode)
994993

995994
static
996995
int unicodeescape_decoding_error(const char **source,
997-
unsigned long *x,
996+
Py_UNICODE *x,
998997
const char *errors,
999998
const char *details)
1000999
{
@@ -1009,7 +1008,7 @@ int unicodeescape_decoding_error(const char **source,
10091008
return 0;
10101009
}
10111010
else if (strcmp(errors,"replace") == 0) {
1012-
*x = (unsigned long)Py_UNICODE_REPLACEMENT_CHARACTER;
1011+
*x = Py_UNICODE_REPLACEMENT_CHARACTER;
10131012
return 0;
10141013
}
10151014
else {
@@ -1063,7 +1062,7 @@ PyObject *PyUnicode_DecodeUnicodeEscape(const char *s,
10631062
end = s + size;
10641063
while (s < end) {
10651064
unsigned char c;
1066-
unsigned long x;
1065+
Py_UNICODE x;
10671066
int i;
10681067

10691068
/* Non-escape characters are interpreted as Unicode ordinals */
@@ -1372,7 +1371,7 @@ PyObject *PyUnicode_DecodeRawUnicodeEscape(const char *s,
13721371
end = s + size;
13731372
while (s < end) {
13741373
unsigned char c;
1375-
unsigned long x;
1374+
Py_UNICODE x;
13761375
int i;
13771376

13781377
/* Non-escape characters are interpreted as Unicode ordinals */

0 commit comments

Comments
 (0)