From 02dcfd842feb9e299bec8a9571a1ee8e8bac6d98 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Mon, 1 Apr 2002 22:58:39 +0000 Subject: [PATCH] (DEC_POS, BUF_DEC_POS): Use BEG_BYTE. Bound the search with MAX_MULTIBYTE_LENGTH to avoid pathological case. --- src/charset.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/charset.h b/src/charset.h index d4e85d91ebf..42ab2308d68 100644 --- a/src/charset.h +++ b/src/charset.h @@ -675,13 +675,15 @@ else \ pos_byte--; \ if (pos_byte < GPT_BYTE) \ - p = BEG_ADDR + pos_byte - 1, p_min = BEG_ADDR; \ + p = BEG_ADDR + pos_byte - BEG_BYTE, p_min = BEG_ADDR; \ else \ - p = BEG_ADDR + GAP_SIZE + pos_byte - 1, p_min = GAP_END_ADDR; \ + p = BEG_ADDR + GAP_SIZE + pos_byte - BEG_BYTE, p_min = GAP_END_ADDR;\ if (p > p_min && !CHAR_HEAD_P (*p)) \ { \ unsigned char *pend = p--; \ int len, bytes; \ + if (p_min < p - MAX_MULTIBYTE_LENGTH) \ + p_min = p - MAX_MULTIBYTE_LENGTH; \ while (p > p_min && !CHAR_HEAD_P (*p)) p--; \ len = pend + 1 - p; \ PARSE_MULTIBYTE_SEQ (p, len, bytes); \ @@ -755,18 +757,20 @@ while (0) pos_byte--; \ if (pos_byte < BUF_GPT_BYTE (buf)) \ { \ - p = BUF_BEG_ADDR (buf) + pos_byte - 1; \ + p = BUF_BEG_ADDR (buf) + pos_byte - BEG_BYTE; \ p_min = BUF_BEG_ADDR (buf); \ } \ else \ { \ - p = BUF_BEG_ADDR (buf) + BUF_GAP_SIZE (buf) + pos_byte - 1; \ + p = BUF_BEG_ADDR (buf) + BUF_GAP_SIZE (buf) + pos_byte - BEG_BYTE;\ p_min = BUF_GAP_END_ADDR (buf); \ } \ if (p > p_min && !CHAR_HEAD_P (*p)) \ { \ unsigned char *pend = p--; \ int len, bytes; \ + if (p_min < p - MAX_MULTIBYTE_LENGTH) \ + p_min = p - MAX_MULTIBYTE_LENGTH; \ while (p > p_min && !CHAR_HEAD_P (*p)) p--; \ len = pend + 1 - p; \ PARSE_MULTIBYTE_SEQ (p, len, bytes); \ -- 2.39.5