Re: [hackers] [dmenu] drw.c: use the same pattern as ellipsis_width to check for infinite recursion || Hiltjo Posthuma

From: NRK <nrk_AT_disroot.org>
Date: Sun, 14 Jul 2024 10:31:55 +0000

> if (!ellipsis_width && render)
> ellipsis_width = drw_fontset_getwidth(drw, "...");
> - if (!invalid_width) {
> - invalid_width = -1; /* stop infinite recursion */
> + if (!invalid_width && render)
> invalid_width = drw_fontset_getwidth(drw, invalid);
> - }

This is what I had initially but this caused some bug because it causes
mismatch between drw_fontset_getwidth() vs the width that actually gets
rendered. On the first call, drw_fontset_getwidth() will calculate the
width with invalid_width being 0 but when rendering it will be non-zero
which messes up some calculation.

I'm also noticing now that if you put an invalid byte at the very end it
fails to render the ellipsis when truncating the text. To reproduce try
to put as many 'a' in there to push the invalid byte *just* beyond the
width of the reigion.

        $ printf "aaaaa....aaaaa\xff" | ./dmenu

I've attached a pic where there should be an ellipsis at the end but
isn't.

I remember testing this case and fixing it by doing the
`invalid_width = -1` thing so that it gets initialized even when not
rendering. But now it happens even after I revert this patch. Weird.
I'll look into what's going wrong here and fix it.

- NRK

buggy.png
(image/png attachment: buggy.png)

Received on Sun Jul 14 2024 - 12:31:55 CEST

This archive was generated by hypermail 2.3.0 : Sun Jul 14 2024 - 12:36:37 CEST