comparison src/coding.c @ 103474:7ead50363544

(decode_coding_iso_2022): Check MSB of bytes more rigidly.
author Kenichi Handa <handa@m17n.org>
date Thu, 18 Jun 2009 10:29:03 +0000
parents 73e7271dee09
children 091a55d2d6f7
comparison
equal deleted inserted replaced
103473:ae2d84ad6135 103474:7ead50363544
3598 coding->annotated = 1; 3598 coding->annotated = 1;
3599 } 3599 }
3600 3600
3601 while (1) 3601 while (1)
3602 { 3602 {
3603 int c1, c2; 3603 int c1, c2, c3;
3604 3604
3605 src_base = src; 3605 src_base = src;
3606 consumed_chars_base = consumed_chars; 3606 consumed_chars_base = consumed_chars;
3607 3607
3608 if (charbuf >= charbuf_end) 3608 if (charbuf >= charbuf_end)
3982 last_id = charset->id; 3982 last_id = charset->id;
3983 last_offset = char_offset; 3983 last_offset = char_offset;
3984 } 3984 }
3985 3985
3986 /* Now we know CHARSET and 1st position code C1 of a character. 3986 /* Now we know CHARSET and 1st position code C1 of a character.
3987 Produce a decoded character while getting 2nd position code 3987 Produce a decoded character while getting 2nd and 3rd
3988 C2 if necessary. */ 3988 position codes C2, C3 if necessary. */
3989 c1 &= 0x7F;
3990 if (CHARSET_DIMENSION (charset) > 1) 3989 if (CHARSET_DIMENSION (charset) > 1)
3991 { 3990 {
3992 ONE_MORE_BYTE (c2); 3991 ONE_MORE_BYTE (c2);
3993 if (c2 < 0x20 || (c2 >= 0x80 && c2 < 0xA0)) 3992 if (c2 < 0x20 || (c2 >= 0x80 && c2 < 0xA0)
3993 || ((c1 & 0x80) != (c2 & 0x80)))
3994 /* C2 is not in a valid range. */ 3994 /* C2 is not in a valid range. */
3995 goto invalid_code; 3995 goto invalid_code;
3996 c1 = (c1 << 8) | (c2 & 0x7F); 3996 if (CHARSET_DIMENSION (charset) == 2)
3997 if (CHARSET_DIMENSION (charset) > 2) 3997 c1 = (c1 << 8) | c2;
3998 else
3998 { 3999 {
3999 ONE_MORE_BYTE (c2); 4000 ONE_MORE_BYTE (c3);
4000 if (c2 < 0x20 || (c2 >= 0x80 && c2 < 0xA0)) 4001 if (c3 < 0x20 || (c3 >= 0x80 && c3 < 0xA0)
4001 /* C2 is not in a valid range. */ 4002 || ((c1 & 0x80) != (c3 & 0x80)))
4003 /* C3 is not in a valid range. */
4002 goto invalid_code; 4004 goto invalid_code;
4003 c1 = (c1 << 8) | (c2 & 0x7F); 4005 c1 = (c1 << 16) | (c2 << 8) | c2;
4004 } 4006 }
4005 } 4007 }
4006 4008 c1 &= 0x7F7F7F;
4007 CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, c1, c); 4009 CODING_DECODE_CHAR (coding, src, src_base, src_end, charset, c1, c);
4008 if (c < 0) 4010 if (c < 0)
4009 { 4011 {
4010 MAYBE_FINISH_COMPOSITION (); 4012 MAYBE_FINISH_COMPOSITION ();
4011 for (; src_base < src; src_base++, char_offset++) 4013 for (; src_base < src; src_base++, char_offset++)