Fix out-of-memory condition in display of long bracketed lines (bug#19322)
commitf3e16cbb5258fcbe2969eb48b332b2c629cfb2a6
authorEli Zaretskii <eliz@gnu.org>
Wed, 10 Dec 2014 17:39:37 +0000 (10 19:39 +0200)
committerEli Zaretskii <eliz@gnu.org>
Wed, 10 Dec 2014 17:42:12 +0000 (10 19:42 +0200)
treeb92dd39f0b8a18caa28da17b09ec62740d2dca1f
parent8bc7ac5c25f42b745cc90131a9a456f763582dbf
Fix out-of-memory condition in display of long bracketed lines (bug#19322)

 src/bidi.c (BIDI_CACHE_MAX_ELTS_PER_SLOT): New macro.
 (bidi_cache_max_elts): New global variable.
 (bidi_shelve_header_size): Add the sizeof bidi_cache_max_elts.
 (bidi_cache_shrink, bidi_initialize): Reset bidi_cache_max_elts to
 its initial value.
 (bidi_cache_search): Handle overflown cache.  Improve commentary.
 (bidi_cache_ensure_space): Limit allocations to the current value
 of bidi_cache_max_elts.  Force xpalloc not to over-allocate.  If
 less than a full BIDI_CACHE_CHUNK is left to the limit, decrease
 the increment to not exceed the limit.
 (bidi_cache_iterator_state): Now returns non-zero if succeeded to
 cache, zero otherwise (meaning the cache overflowed).  In the
 latter case, set bidi_cache_last_idx to -1.
 (bidi_peek_at_next_level): Handle overflown cache.
 (bidi_push_it): Increase the cache limit for iterating the new
 object.
 (bidi_pop_it): Decrease the cache limit back to previous value.
 (bidi_shelve_cache): Shelve the current value of the cache limit.
 (bidi_unshelve_cache): Restore the value of cache limit.
 (bidi_find_bracket_pairs): If the cache overflows while looking
 for the paired bracket, give up and let bidi_resolve_neutrals
 process the bracket as a simple neutral.
 (bidi_find_other_level_edge): If the cache overflows, fall back on
 Plan B, which effectively stops the reordering and restarts it on
 the next character (after resetting the cache).
 (bidi_move_to_visually_next): When the cache overflows, reset it
 after processing the last cached character.
src/ChangeLog
src/bidi.c