comparison 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
comparison
equal deleted inserted replaced
80214:e6d0951f412a 80217:8d5c147f030d
789 return NULL; 789 return NULL;
790 } 790 }
791 /* Try decoding a single surrogate character. If 791 /* Try decoding a single surrogate character. If
792 there are more, let the codec call us again. */ 792 there are more, let the codec call us again. */
793 p += start; 793 p += start;
794 if (strlen(p) > 2 && 794 if (PyBytes_GET_SIZE(object) - start >= 3 &&
795 ((p[0] & 0xf0) == 0xe0 || 795 (p[0] & 0xf0) == 0xe0 &&
796 (p[1] & 0xc0) == 0x80 || 796 (p[1] & 0xc0) == 0x80 &&
797 (p[2] & 0xc0) == 0x80)) { 797 (p[2] & 0xc0) == 0x80) {
798 /* it's a three-byte code */ 798 /* it's a three-byte code */
799 ch = ((p[0] & 0x0f) << 12) + ((p[1] & 0x3f) << 6) + (p[2] & 0x3f); 799 ch = ((p[0] & 0x0f) << 12) + ((p[1] & 0x3f) << 6) + (p[2] & 0x3f);
800 if (ch < 0xd800 || ch > 0xdfff) 800 if (ch < 0xd800 || ch > 0xdfff)
801 /* it's not a surrogate - fail */ 801 /* it's not a surrogate - fail */
802 ch = 0; 802 ch = 0;