Subject: Re: bug#77065: 31.0.50; Infinite loop in move_it_to

From: Eli Zaretskii <[email-masked]>
Date: Thu, 20 Mar 2025 12:39:50 +0200

> Date: Mon, 17 Mar 2025 19:36:15 -0700
> Cc: [email-masked]
> From: Yifan Zhu <[email-masked]>
> 
> On 3/17/25 7:27 AM, Eli Zaretskii wrote:
> > Thanks, but I don't have access to a system where these prerequisites
> > can be met.  So either someone can reproduce this, debug the problem,
> > and describe the reason for the loop, or I'd need to ask you to do it,
> > if possible.  Or, if you can show a recipe for reproducing the problem
> > without installing LaTeX and xenops, I could try reproducing this on
> > the systems to which I have access.
> 
> Right now I have a conjecture about what might be causing the infinite 
> loop -- when line number are produced, we can no longer use it->hpos == 
> 0 to test if the glyph is the first glyph. Perhaps this is best 
> explained by the following diff:

Thanks for pointing out this issue.

The diff as posted is not entirely correct, since
move_it_in_display_line_to can be called in the middle of a line, and
then it is wrong to assume that the initial hpos is zero.  But the
patch below should fix this particular problem, I think; please try
it and tell if it avoids the infloop.

diff --git a/src/xdisp.c b/src/xdisp.c
index c396b213..90ec187 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -10295,10 +10295,10 @@ #define IT_RESET_X_ASCENT_DESCENT(IT)			\
 		{
 		  bool moved_forward = false;
 
-		  if (/* IT->hpos == 0 means the very first glyph
-			 doesn't fit on the line, e.g. a wide
-			 image.  */
-		      it->hpos == 0
+		  if (/* IT->hpos == 0 (modulo line-number width) means
+			 the very first glyph doesn't fit on the line,
+			 e.g., a wide image.  */
+		      it->hpos == 0 + (it->lnum_width ? it->lnum_width + 2 : 0)
 		      || (new_x == it->last_visible_x
 			  && FRAME_WINDOW_P (it->f)))
 		    {