changeset 21945:bda081af77e7

(boyer_moore): Check more reliably for ptr[1] being out of range. Use pat_end to point at the pattern's end.
author Richard M. Stallman <rms@gnu.org>
date Tue, 05 May 1998 06:25:58 +0000
parents 8e606f5208eb
children b22c98ed245f
files src/search.c
diffstat 1 files changed, 12 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/search.c	Tue May 05 04:25:03 1998 +0000
+++ b/src/search.c	Tue May 05 06:25:58 1998 +0000
@@ -1520,7 +1520,7 @@
   int *BM_tab_base;
   register unsigned char *cursor, *p_limit;  
   register int i, j;
-  unsigned char *pat;
+  unsigned char *pat, *pat_end;
   int multibyte = ! NILP (current_buffer->enable_multibyte_characters);
 
   unsigned char simple_translate[0400];
@@ -1562,10 +1562,15 @@
 
   dirlen = len_byte * direction;
   infinity = dirlen - (lim_byte + pos_byte + len_byte + len_byte) * direction;
+
+  /* Record position after the end of the pattern.  */
+  pat_end = base_pat + len_byte;
+  /* BASE_PAT points to a character that we start scanning from.
+     It is the first character in a forward search,
+     the last character in a backward search.  */
   if (direction < 0)
-    pat = (base_pat += len_byte - 1);
-  else
-    pat = base_pat;
+    base_pat = pat_end - 1;
+
   BM_tab_base = BM_tab;
   BM_tab += 0400;
   j = dirlen;		/* to get it in a register */
@@ -1589,7 +1594,7 @@
   i = 0;
   while (i != infinity)
     {
-      unsigned char *ptr = pat + i;
+      unsigned char *ptr = base_pat + i;
       i += direction;
       if (i == dirlen)
 	i = infinity;
@@ -1600,7 +1605,8 @@
 	  int this_translated = 1;
 
 	  if (multibyte
-	      && (ptr + 1 == pat + len_byte || CHAR_HEAD_P (ptr[1])))
+	      /* Is *PTR the last byte of a character?  */
+	      && (pat_end - ptr == 1 || CHAR_HEAD_P (ptr[1])))
 	    {
 	      unsigned char *charstart = ptr;
 	      while (! CHAR_HEAD_P (*charstart))