diff Python/codecs.c @ 80218:e4aedd239e45

#16336: merge with 3.3.
author Ezio Melotti <ezio.melotti@gmail.com>
date Sat, 03 Nov 2012 23:05:18 +0200
parents 13dd8199c112 8d5c147f030d
children 3a86a3f1d89a
line wrap: on
line diff
--- a/Python/codecs.c	Sat Nov 03 21:36:22 2012 +0200
+++ b/Python/codecs.c	Sat Nov 03 23:05:18 2012 +0200
@@ -791,10 +791,10 @@
         /* Try decoding a single surrogate character. If
            there are more, let the codec call us again. */
         p += start;
-        if (strlen(p) > 2 &&
-            ((p[0] & 0xf0) == 0xe0 ||
-             (p[1] & 0xc0) == 0x80 ||
-             (p[2] & 0xc0) == 0x80)) {
+        if (PyBytes_GET_SIZE(object) - start >= 3 &&
+            (p[0] & 0xf0) == 0xe0 &&
+            (p[1] & 0xc0) == 0x80 &&
+            (p[2] & 0xc0) == 0x80) {
             /* it's a three-byte code */
             ch = ((p[0] & 0x0f) << 12) + ((p[1] & 0x3f) << 6) + (p[2] & 0x3f);
             if (!Py_UNICODE_IS_SURROGATE(ch))