Subject: Re: bug#61704: 29.0.60; Crash in get_narrowed_begv

From: martin rudalics <[email-masked]>
Date: Thu, 23 Feb 2023 10:33:42 +0100

>> I found a way to get such small windows: set window-min-width,
 >> window-min-height, window-safe-min-width and window-safe-min-heigth to 0.
 >> Of course doing that ignores the fact that the docstring of the
 >> window-safe-min-* variables say that "Anything less might crash Emacs",
 >> and that their values are 2 (width) and 1 (height).  Which makes me wonder
 >> why these variables can be changed / exist.
 >
 > Maybe Martin (CC'ed) can answer that.

I don't recall the details - if memory doesn't deceive me, the "Anything
less might crash Emacs" phrase was coined by Kim, albeit in a different
context.

These variables exist and can be changed because at the time they were
implemented, there was no real consensus as to which sizes could really
crash Emacs.  The window code itself does not care and the redisplay
code is nowhere explicit about it.

Nowadays these variables are a bad idea because they count (1) lines and
columns and (2) represent total window sizes.  (1) is hampered by the
fact that we now remap faces (do we know whether the return value of
'window-safe-min-pixel-height' is meaningful in such case?) and (2) is
hampered by the presence of window decorations whose sizes are more and
more undetermined so we have to apply brute force measures like

   /* Don't return a negative value.  */
   return max (height / denom, 0);

which appear amateurish (aren't we able to calculate 'height' correctly
in the first place?).

But the real problem here seems that resize_frame_windows has to do what
frame resizing wants and (as _might_ happen with Po's ediff control
frame) there's no guarantee that 'height' is really greater than zero
(or one) there.

So OT1H we really should set proper minimum size hints for the WM to
avoid that resize_frame_windows has to deal with frame sizes it
intrinsically cannot handle and OTOH the redisplay engine should be able
to handle zero window sizes to avoid crashes the window code cannot
prevent.

martin