From 6b21de180fba10432988d94d2b8f3e2521be5b17 Mon Sep 17 00:00:00 2001 From: Chong Yidong Date: Wed, 23 Nov 2011 14:47:09 +0800 Subject: [PATCH] * xdisp.c (compute_stop_pos): Check validity of end_charpos before using it. Fixes: debbugs:5984 --- src/ChangeLog | 5 +++++ src/xdisp.c | 10 +++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 51fa3b65be1..d26b893ced1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2011-11-23 Chong Yidong + + * xdisp.c (compute_stop_pos): Check validity of end_charpos before + using it (Bug#5984). + 2011-11-22 Eli Zaretskii * dispnew.c (adjust_glyph_matrix): Don't verify hash code of mode- diff --git a/src/xdisp.c b/src/xdisp.c index 8a8c1d08994..403272e7d0c 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -3166,13 +3166,11 @@ compute_stop_pos (struct it *it) Lisp_Object object, limit, position; EMACS_INT charpos, bytepos; - /* If nowhere else, stop at the end. */ - it->stop_charpos = it->end_charpos; - if (STRINGP (it->string)) { /* Strings are usually short, so don't limit the search for properties. */ + it->stop_charpos = it->end_charpos; object = it->string; limit = Qnil; charpos = IT_STRING_CHARPOS (*it); @@ -3182,6 +3180,12 @@ compute_stop_pos (struct it *it) { EMACS_INT pos; + /* If end_charpos is out of range for some reason, such as a + misbehaving display function, rationalize it (Bug#5984). */ + if (it->end_charpos > ZV) + it->end_charpos = ZV; + it->stop_charpos = it->end_charpos; + /* If next overlay change is in front of the current stop pos (which is IT->end_charpos), stop there. Note: value of next_overlay_change is point-max if no overlay change -- 2.11.4.GIT