diff Python/codecs.c @ 80217:8d5c147f030d 3.3

#16336: merge with 3.2.
author Ezio Melotti <ezio.melotti@gmail.com>
date Sat, 03 Nov 2012 23:04:41 +0200
parents fd41c6b4de57 18ed608ee594
children e4aedd239e45
line wrap: on
line diff
--- a/Python/codecs.c	Sat Nov 03 21:32:55 2012 +0200
+++ b/Python/codecs.c	Sat Nov 03 23:04:41 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 (ch < 0xd800 || ch > 0xdfff)