From: Eli Zaretskii Date: Wed, 19 May 2010 07:22:41 +0000 (+0300) Subject: Fix bug #6210. X-Git-Tag: emacs-pretest-24.0.90~104^2~275^2~438^2~205^2~57 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=ead6f8f50b3d538902ad33421973be783cbea969;p=emacs.git Fix bug #6210. bidi.c (bidi_cache_shrink, bidi_cache_iterator_state): Fix reallocation of the cache. --- diff --git a/src/ChangeLog b/src/ChangeLog index 8a5d5b9fb84..7c59d6b6545 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2010-05-19 Eli Zaretskii + + * bidi.c (bidi_cache_shrink, bidi_cache_iterator_state): Fix + reallocation of the cache. (Bug#6210) + 2010-05-19 Glenn Morris * s/msdos.h (ORDINARY_LINK): Move to sed2v2.inp. diff --git a/src/bidi.c b/src/bidi.c index dbc95608fea..6bcbf6f6aea 100644 --- a/src/bidi.c +++ b/src/bidi.c @@ -543,6 +543,7 @@ bidi_copy_it (struct bidi_it *to, struct bidi_it *from) #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 @@ bidi_cache_shrink (void) { 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 @@ bidi_cache_iterator_state (struct bidi_it *bidi_it, int resolved) /* 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