changeset 108697:ba70090bc778

Fix bug #6210. bidi.c (bidi_cache_shrink, bidi_cache_iterator_state): Fix reallocation of the cache.
author Eli Zaretskii <eliz@gnu.org>
date Wed, 19 May 2010 10:22:41 +0300
parents 144e6ea330f0
children 7be123ae7612 f3352dc3107f
files src/ChangeLog src/bidi.c
diffstat 2 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Tue May 18 23:06:48 2010 -0400
+++ b/src/ChangeLog	Wed May 19 10:22:41 2010 +0300
@@ -1,3 +1,8 @@
+2010-05-19  Eli Zaretskii  <eliz@gnu.org>
+
+	* bidi.c (bidi_cache_shrink, bidi_cache_iterator_state): Fix
+	reallocation of the cache.  (Bug#6210)
+
 2010-05-19  Glenn Morris  <rgm@gnu.org>
 
 	* s/msdos.h (ORDINARY_LINK): Move to sed2v2.inp.
--- a/src/bidi.c	Tue May 18 23:06:48 2010 -0400
+++ b/src/bidi.c	Wed May 19 10:22:41 2010 +0300
@@ -543,6 +543,7 @@
 #define BIDI_CACHE_CHUNK 200
 static struct bidi_it *bidi_cache;
 static size_t bidi_cache_size = 0;
+static size_t elsz = sizeof (struct bidi_it);
 static int bidi_cache_idx;	/* next unused cache slot */
 static int bidi_cache_last_idx;	/* slot of last cache hit */
 
@@ -558,8 +559,9 @@
 {
   if (bidi_cache_size > BIDI_CACHE_CHUNK)
     {
-      bidi_cache_size = BIDI_CACHE_CHUNK * sizeof (struct bidi_it);
-      bidi_cache = (struct bidi_it *) xrealloc (bidi_cache, bidi_cache_size);
+      bidi_cache_size = BIDI_CACHE_CHUNK;
+      bidi_cache =
+	(struct bidi_it *) xrealloc (bidi_cache, bidi_cache_size * elsz);
     }
   bidi_cache_reset ();
 }
@@ -688,9 +690,9 @@
       /* Enlarge the cache as needed.  */
       if (idx >= bidi_cache_size)
 	{
-	  bidi_cache_size += BIDI_CACHE_CHUNK * sizeof (struct bidi_it);
+	  bidi_cache_size += BIDI_CACHE_CHUNK;
 	  bidi_cache =
-	    (struct bidi_it *) xrealloc (bidi_cache, bidi_cache_size);
+	    (struct bidi_it *) xrealloc (bidi_cache, bidi_cache_size * elsz);
 	}
       /* Character positions should correspond to cache positions 1:1.
 	 If we are outside the range of cached positions, the cache is