]> granicus.if.org Git - python/commitdiff
When decoding UTF-16, don't assume that the buffer is in native endianness
authorMartin v. Löwis <martin@v.loewis.de>
Tue, 26 Jun 2001 22:43:40 +0000 (22:43 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Tue, 26 Jun 2001 22:43:40 +0000 (22:43 +0000)
when checking surrogates.

Objects/unicodeobject.c

index 7dc370a48d423d8bb1f803666023f5383106c182..ffac3710df4062bfa6314516d9699008c22ec689 100644 (file)
@@ -1065,16 +1065,16 @@ PyObject *PyUnicode_DecodeUTF16(const char *s,
            errmsg = "unexpected end of data";
            goto utf16Error;
        }
-       if (0xDC00 <= *q && *q <= 0xDFFF) {
+       if (0xD800 <= ch && ch <= 0xDBFF) {
            Py_UCS2 ch2 = *q++;
 #ifdef BYTEORDER_IS_LITTLE_ENDIAN
            if (bo == 1)
-                   ch = (ch >> 8) | (ch << 8);
+                   ch2 = (ch2 >> 8) | (ch2 << 8);
 #else    
            if (bo == -1)
-                   ch = (ch >> 8) | (ch << 8);
+                   ch2 = (ch2 >> 8) | (ch2 << 8);
 #endif
-           if (0xD800 <= ch && ch <= 0xDBFF) {
+           if (0xDC00 <= ch2 && ch2 <= 0xDFFF) {
 #if Py_UNICODE_SIZE == 2
                /* This is valid data (a UTF-16 surrogate pair), but
                   we are not able to store this information since our