Subject: bug#56561: 29.0.50; Infloop in try_window

From: Eli Zaretskii <[email-masked]>
Date: Sun, 17 Jul 2022 16:29:02 +0300

> From: Po Lu <[email-masked]>
> Cc: [email-masked],  [email-masked]
> Date: Sun, 17 Jul 2022 15:43:00 +0800
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> > More than 40 screen lines of canonical characters?  Please show a
> > recipe for reproducing this.
> 
> Place the following text in a buffer
> 
> <a href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHgAAAB4CAIAAAC2BqGFAAABhWlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw1AUhU9TpSIVETuIOGSo4mChqIijVqEIFUKt0KqDyUt/hCYNSYqLo+BacPBnserg4qyrg6sgCP6AODo5KbpIifclhRYxPri8j/PeOdx3HyDUy0yzOuKApttmOpkQs7kVMfSKEPqoRhGXmWXMSlIKvuvrHgG+38V4lv+9P1ePmrcYEBCJZ5hh2sTrxFObtsF5nzjCSrJKfE48ZlKDxI9cVzx+41x0WeCZETOTniOOEIvFNlbamJVMjXiSOKpqOuULWY9VzluctXKVNfvkLwzn9eUlrlMNIYkFLEKCCAVVbKAMGzHadVIspOk84eMfdP0SuRRybYCRYx4VaJBdP/gf/J6tVZgY95LCCaDzxXE+hoHQLtCoOc73seM0ToDgM3Clt/yVOjD9SXqtpUWPgN5t4OK6pSl7wOUOMPBkyKbsSkEqoVAA3s/om3JA/y3QverNrXmO0wcgQ7NK3QAHh8BIkbLXfN7d1T63f+805/cDmFJytmmECVUAAAAJcEhZcwAALiMAAC4jAXilP3YAAAAHdElNRQfmBxEHKRAK8iffAAAAGXRFWHRDb21tZW50AENyZWF0ZWQgd2l0aCBHSU1QV4EOFwAAC6ZJREFUeNrtnW1z2kYQgHfvRQhhAsR1XsBpM9OmH/r/f0tnmqSZNDbYietgCkhIurvthwMhCMYkFnCyuQ+ZjA0YPZxXe8/trZGI4DC2P9gBwQH0AfRhHEAfQB9AH8ZOhsj+Z5JEjcfJzY0KQwA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794N//zTnhC2GyW8XheNhvudMdxUfatBjz5+HH/4ALlTF8i5HgzAGNFqbaMYw9lRlOpbATrsdsNPnxaTTI5EZIweDgFAtFoud8ZwU/WtAJ3/TQEAEAIBiIgBGAA9HHovXrjcGWNfqi/t9/WnT3avjvn++N27+h9/PHnzZrP0TggkAmNASgJgACSl450x9qKfVL+vh0MQOZ5E4w8fmJRHr1/fARqFYADT6JOmIKXl/ggpr2c9pcwYcg6L+jT89IlJGXQ6t4JmQhgiMoZ5nkkSAECb2Nn+I1suxiiX6ptSlhIZQyEW5jVA1OvdChqFgFmLCZMkzPPIBhAAANhNMUaJVJ/tb4GMoech58j5EuvVoaPabke9noXKshRmls3Ufv3VPzkp+59YL1b1oRAohA0dKCVyzuxX1oMOOh074S1rnssogp9/tqH9MPKqj9uloN2M5px5nu3bwnKsV4eOjDXkKFfb7WAxdX/kI1N94/fvZ/gZItrVHJMSpczmtSttJEo8iAZv347//nvmoxAQM8pMSjtBD6CLGaOPH5eW03nKhxld5Ai73aVFdT7YHkDv6uZ5QLCb8T+jZg5A8TH4MwAAAABJRU5ErkJggg==">View image</a>
> 
> and type "M-x shr-render-buffer RET".  The tooltip on top of "View
> image" will be larger than the size limit.

Thanks.  The patch below is what I had in mind.  WDYT?

diff --git a/src/w32fns.c b/src/w32fns.c
index 51540e1..5e42a1d 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -7568,7 +7568,23 @@ DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
   clear_glyph_matrix (w->desired_matrix);
   clear_glyph_matrix (w->current_matrix);
   SET_TEXT_POS (pos, BEGV, BEGV_BYTE);
-  try_window (window, pos, TRY_WINDOW_IGNORE_FONTS_CHANGE);
+  bool displayed = try_window (window, pos, TRY_WINDOW_IGNORE_FONTS_CHANGE);
+  if (!displayed && NILP (Vx_max_tooltip_size))
+    {
+#ifdef ENABLE_CHECKING
+      struct glyph_row *row = w->desired_matrix->rows;
+      struct glyph_row *end =
+	w->desired_matrix->rows + w->desired_matrix->nrows;
+      while (row < end)
+	{
+	  if (!row->displays_text_p
+	      || row->ends_at_zv_p)
+	    break;
+	  ++row;
+	}
+      eassert (row < end && row->ends_at_zv_p);
+#endif
+    }
   /* Calculate size of tooltip window.  */
   size = Fwindow_text_pixel_size (window, Qnil, Qnil, Qnil,
 				  make_fixnum (w->pixel_height), Qnil,
@@ -10770,7 +10786,7 @@ syms_of_w32fns (void)
 
   DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size,
 	       doc: /* SKIP: real doc in xfns.c.  */);
-  Vx_max_tooltip_size = Fcons (make_fixnum (80), make_fixnum (40));
+  Vx_max_tooltip_size = Qnil;
 
   DEFVAR_LISP ("x-no-window-manager", Vx_no_window_manager,
 	       doc: /* SKIP: real doc in xfns.c.  */);