# HG changeset patch # User Stefan Monnier # Date 1017701919 0 # Node ID fcc0f55d734fd28f0a1b36047bf393c238dfebdc # Parent fca902769bf4be1ee8d3fca75ae159832803670b (DEC_POS, BUF_DEC_POS): Use BEG_BYTE. Bound the search with MAX_MULTIBYTE_LENGTH to avoid pathological case. diff -r fca902769bf4 -r fcc0f55d734f src/charset.h --- a/src/charset.h Mon Apr 01 22:54:03 2002 +0000 +++ b/src/charset.h Mon Apr 01 22:58:39 2002 +0000 @@ -675,13 +675,15 @@ \ 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 @@ 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); \