changeset 107655:0958f6c3f7c6

Fix a crash of I-search in a bidi-reordered buffer. bidi.c (bidi_cache_iterator_state): Invalidate the cache if we are outside the range of cached character positions.
author Eli Zaretskii <eliz@gnu.org>
date Tue, 30 Mar 2010 19:29:02 +0300
parents 9a8d281f69fd
children a788d758fe0a
files src/ChangeLog src/bidi.c
diffstat 2 files changed, 15 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Tue Mar 30 19:10:14 2010 +0300
+++ b/src/ChangeLog	Tue Mar 30 19:29:02 2010 +0300
@@ -1,3 +1,8 @@
+2010-03-30  Eli Zaretskii  <eliz@gnu.org>
+
+	* bidi.c (bidi_cache_iterator_state): Invalidate the cache if we
+	are outside the range of cached character positions.
+
 2010-03-30  Juanma Barranquero  <lekktu@gmail.com>
 
 	* makefile.w32-in ($(BLD)/bidi.$(O)): Add dependency on w32gui.h.
--- a/src/bidi.c	Tue Mar 30 19:10:14 2010 +0300
+++ b/src/bidi.c	Tue Mar 30 19:29:02 2010 +0300
@@ -671,10 +671,16 @@
       /* Don't overrun the cache limit.  */
       if (idx > sizeof (bidi_cache) / sizeof (bidi_cache[0]) - 1)
 	abort ();
-      /* Don't violate cache integrity: character positions should
-	 correspond to cache positions 1:1.  */
-      if (idx > 0 && bidi_it->charpos != bidi_cache[idx - 1].charpos + 1)
-	abort ();
+      /* Character positions should correspond to cache positions 1:1.
+	 If we are outside the range of cached positions, the cache is
+	 useless and must be reset.  */
+      if (idx > 0 &&
+	  (bidi_it->charpos > bidi_cache[idx - 1].charpos + 1
+	   || bidi_it->charpos < bidi_cache[0].charpos))
+	{
+	  bidi_cache_reset ();
+	  idx = 0;
+	}
       bidi_copy_it (&bidi_cache[idx], bidi_it);
       if (!resolved)
 	bidi_cache[idx].resolved_level = -1;