diff options
| author | Richard M. Stallman | 1998-05-05 06:25:58 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-05-05 06:25:58 +0000 |
| commit | cb6792d2dbc65e1fcf63a45e82b3d8ac35e8313f (patch) | |
| tree | 38d8fe02d5ec9425ecd9e01194ca420918d50b34 /src | |
| parent | 42b1fc290dc2570117a67d3a28b52452d9f35420 (diff) | |
| download | emacs-cb6792d2dbc65e1fcf63a45e82b3d8ac35e8313f.tar.gz emacs-cb6792d2dbc65e1fcf63a45e82b3d8ac35e8313f.zip | |
(boyer_moore): Check more reliably for ptr[1] being
out of range. Use pat_end to point at the pattern's end.
Diffstat (limited to 'src')
| -rw-r--r-- | src/search.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/search.c b/src/search.c index c3b873353da..225155d73ac 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -1520,7 +1520,7 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt, | |||
| 1520 | int *BM_tab_base; | 1520 | int *BM_tab_base; |
| 1521 | register unsigned char *cursor, *p_limit; | 1521 | register unsigned char *cursor, *p_limit; |
| 1522 | register int i, j; | 1522 | register int i, j; |
| 1523 | unsigned char *pat; | 1523 | unsigned char *pat, *pat_end; |
| 1524 | int multibyte = ! NILP (current_buffer->enable_multibyte_characters); | 1524 | int multibyte = ! NILP (current_buffer->enable_multibyte_characters); |
| 1525 | 1525 | ||
| 1526 | unsigned char simple_translate[0400]; | 1526 | unsigned char simple_translate[0400]; |
| @@ -1562,10 +1562,15 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt, | |||
| 1562 | 1562 | ||
| 1563 | dirlen = len_byte * direction; | 1563 | dirlen = len_byte * direction; |
| 1564 | infinity = dirlen - (lim_byte + pos_byte + len_byte + len_byte) * direction; | 1564 | infinity = dirlen - (lim_byte + pos_byte + len_byte + len_byte) * direction; |
| 1565 | |||
| 1566 | /* Record position after the end of the pattern. */ | ||
| 1567 | pat_end = base_pat + len_byte; | ||
| 1568 | /* BASE_PAT points to a character that we start scanning from. | ||
| 1569 | It is the first character in a forward search, | ||
| 1570 | the last character in a backward search. */ | ||
| 1565 | if (direction < 0) | 1571 | if (direction < 0) |
| 1566 | pat = (base_pat += len_byte - 1); | 1572 | base_pat = pat_end - 1; |
| 1567 | else | 1573 | |
| 1568 | pat = base_pat; | ||
| 1569 | BM_tab_base = BM_tab; | 1574 | BM_tab_base = BM_tab; |
| 1570 | BM_tab += 0400; | 1575 | BM_tab += 0400; |
| 1571 | j = dirlen; /* to get it in a register */ | 1576 | j = dirlen; /* to get it in a register */ |
| @@ -1589,7 +1594,7 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt, | |||
| 1589 | i = 0; | 1594 | i = 0; |
| 1590 | while (i != infinity) | 1595 | while (i != infinity) |
| 1591 | { | 1596 | { |
| 1592 | unsigned char *ptr = pat + i; | 1597 | unsigned char *ptr = base_pat + i; |
| 1593 | i += direction; | 1598 | i += direction; |
| 1594 | if (i == dirlen) | 1599 | if (i == dirlen) |
| 1595 | i = infinity; | 1600 | i = infinity; |
| @@ -1600,7 +1605,8 @@ boyer_moore (n, base_pat, len, len_byte, trt, inverse_trt, | |||
| 1600 | int this_translated = 1; | 1605 | int this_translated = 1; |
| 1601 | 1606 | ||
| 1602 | if (multibyte | 1607 | if (multibyte |
| 1603 | && (ptr + 1 == pat + len_byte || CHAR_HEAD_P (ptr[1]))) | 1608 | /* Is *PTR the last byte of a character? */ |
| 1609 | && (pat_end - ptr == 1 || CHAR_HEAD_P (ptr[1]))) | ||
| 1604 | { | 1610 | { |
| 1605 | unsigned char *charstart = ptr; | 1611 | unsigned char *charstart = ptr; |
| 1606 | while (! CHAR_HEAD_P (*charstart)) | 1612 | while (! CHAR_HEAD_P (*charstart)) |