From df80c7f014d343a8256136361203b731a95198f9 Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Tue, 21 Apr 2009 06:36:21 +0000 Subject: [PATCH] (decode_coding_utf_16): Reduce charbuf_end for the worst case. (decode_coding_emacs_mule, decode_coding_iso_2022) (decode_coding_sjis, decode_coding_big5, decode_coding_charset): Likewise. --- src/ChangeLog | 8 ++++++++ src/coding.c | 25 ++++++++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index cdde8a597f2..378bce3a07b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2009-04-21 Kenichi Handa + + * coding.c (decode_coding_utf_16): Reduce charbuf_end for the + worst case. + (decode_coding_emacs_mule, decode_coding_iso_2022) + (decode_coding_sjis, decode_coding_big5, decode_coding_charset): + Likewise. + 2009-04-19 Jason Rumney The following changes fix Bug#3005 for wide glyphs on each platform, diff --git a/src/coding.c b/src/coding.c index 99f5ed8f805..d8bee597756 100644 --- a/src/coding.c +++ b/src/coding.c @@ -1703,7 +1703,8 @@ decode_coding_utf_16 (coding) const unsigned char *src_end = coding->source + coding->src_bytes; const unsigned char *src_base; int *charbuf = coding->charbuf + coding->charbuf_used; - int *charbuf_end = coding->charbuf + coding->charbuf_size; + /* We may produces at most 3 chars in one loop. */ + int *charbuf_end = coding->charbuf + coding->charbuf_size - 2; int consumed_chars = 0, consumed_chars_base = 0; int multibytep = coding->src_multibyte; enum utf_bom_type bom = CODING_UTF_16_BOM (coding); @@ -1749,7 +1750,7 @@ decode_coding_utf_16 (coding) src_base = src; consumed_chars_base = consumed_chars; - if (charbuf + 2 >= charbuf_end) + if (charbuf >= charbuf_end) { if (byte_after_cr1 >= 0) src_base -= 2; @@ -2442,8 +2443,10 @@ decode_coding_emacs_mule (coding) const unsigned char *src_end = coding->source + coding->src_bytes; const unsigned char *src_base; int *charbuf = coding->charbuf + coding->charbuf_used; + /* We may produce two annocations (charset and composition) in one + loop and one more charset annocation at the end. */ int *charbuf_end - = coding->charbuf + coding->charbuf_size - MAX_ANNOTATION_LENGTH; + = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 3); int consumed_chars = 0, consumed_chars_base; int multibytep = coding->src_multibyte; Lisp_Object attrs, charset_list; @@ -3558,8 +3561,10 @@ decode_coding_iso_2022 (coding) const unsigned char *src_end = coding->source + coding->src_bytes; const unsigned char *src_base; int *charbuf = coding->charbuf + coding->charbuf_used; + /* We may produce two annocations (charset and composition) in one + loop and one more charset annocation at the end. */ int *charbuf_end - = coding->charbuf + coding->charbuf_size - MAX_ANNOTATION_LENGTH; + = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 3); int consumed_chars = 0, consumed_chars_base; int multibytep = coding->src_multibyte; /* Charsets invoked to graphic plane 0 and 1 respectively. */ @@ -4758,8 +4763,10 @@ decode_coding_sjis (coding) const unsigned char *src_end = coding->source + coding->src_bytes; const unsigned char *src_base; int *charbuf = coding->charbuf + coding->charbuf_used; + /* We may produce one charset annocation in one loop and one more at + the end. */ int *charbuf_end - = coding->charbuf + coding->charbuf_size - MAX_ANNOTATION_LENGTH; + = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 2); int consumed_chars = 0, consumed_chars_base; int multibytep = coding->src_multibyte; struct charset *charset_roman, *charset_kanji, *charset_kana; @@ -4875,8 +4882,10 @@ decode_coding_big5 (coding) const unsigned char *src_end = coding->source + coding->src_bytes; const unsigned char *src_base; int *charbuf = coding->charbuf + coding->charbuf_used; + /* We may produce one charset annocation in one loop and one more at + the end. */ int *charbuf_end - = coding->charbuf + coding->charbuf_size - MAX_ANNOTATION_LENGTH; + = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 2); int consumed_chars = 0, consumed_chars_base; int multibytep = coding->src_multibyte; struct charset *charset_roman, *charset_big5; @@ -5549,8 +5558,10 @@ decode_coding_charset (coding) const unsigned char *src_end = coding->source + coding->src_bytes; const unsigned char *src_base; int *charbuf = coding->charbuf + coding->charbuf_used; + /* We may produce one charset annocation in one loop and one more at + the end. */ int *charbuf_end - = coding->charbuf + coding->charbuf_size - MAX_ANNOTATION_LENGTH; + = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 2); int consumed_chars = 0, consumed_chars_base; int multibytep = coding->src_multibyte; Lisp_Object attrs, charset_list, valids; -- 2.39.2