From c54238db6aabeb5ebc74ee60af65a8af27aa6426 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Tue, 26 Jul 2016 18:27:21 +0300 Subject: [PATCH] Avoid segfaults in compute_motion * src/indent.c (compute_motion): Don't turn on and don't use the width cache unless the buffer's width-table is non-nil. This avoids segfaults because code that uses the width cache assumes the width-table exists. (Bug#24064) --- src/indent.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/indent.c b/src/indent.c index bc59239f20f..1015259cedd 100644 --- a/src/indent.c +++ b/src/indent.c @@ -1162,7 +1162,7 @@ compute_motion (ptrdiff_t from, ptrdiff_t frombyte, EMACS_INT fromvpos, int prev_tab_offset; /* Previous tab offset. */ int continuation_glyph_width; struct buffer *cache_buffer = current_buffer; - struct region_cache *width_cache; + struct region_cache *width_cache = NULL; struct composition_it cmp_it; @@ -1170,11 +1170,14 @@ compute_motion (ptrdiff_t from, ptrdiff_t frombyte, EMACS_INT fromvpos, if (cache_buffer->base_buffer) cache_buffer = cache_buffer->base_buffer; - width_cache = width_run_cache_on_off (); if (dp == buffer_display_table ()) - width_table = (VECTORP (BVAR (current_buffer, width_table)) - ? XVECTOR (BVAR (current_buffer, width_table))->contents - : 0); + { + width_table = (VECTORP (BVAR (current_buffer, width_table)) + ? XVECTOR (BVAR (current_buffer, width_table))->contents + : 0); + if (width_table) + width_cache = width_run_cache_on_off (); + } else /* If the window has its own display table, we can't use the width run cache, because that's based on the buffer's display table. */ -- 2.39.2