From: Jochen Sprickerhof <[email protected]>
In case lpad * 2 > w, w - lpad * 2 wraps around and comparing it with ew
is always true.
Also shorten the text if the initial width does not fit with padding.
---
drw.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drw.c b/drw.c
index 9c39086..36b56df 100644
--- a/drw.c
+++ b/drw.c
@@ -310,8 +310,8 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned
int h, unsigned int lp
if (utf8strlen) {
drw_font_getexts(usedfont, utf8str, utf8strlen, &ew,
NULL);
/* shorten text if necessary */
- if (ew > w)
- for (ew = 0, len = 0; ew < w - lpad * 2 && len
< MIN(utf8strlen, sizeof(buf) - 1); len++)
+ if (ew + lpad * 2 > w)
+ for (ew = 0, len = 0; ew + lpad * 2 < w && len
< MIN(utf8strlen, sizeof(buf) - 1); len++)
drw_font_getexts(usedfont, utf8str,
len, &ew, NULL);
else
len = MIN(utf8strlen, sizeof(buf) - 1);
--
2.32.0