drw_text: don't segfault when called with 0 width
authorNRK <nrk@disroot.org>
Sun, 27 Mar 2022 19:02:52 +0000 (01:02 +0600)
committerHiltjo Posthuma <hiltjo@codemadness.org>
Sat, 16 Apr 2022 14:21:01 +0000 (16:21 +0200)
this patch just rejects *any* 0 width draws, which is surely an error by
the caller.

this also guards against cases where the width is too small for the
ellipsis to fit, so ellipsis_w will remain 0.
reported by Bakkeby <bakkeby@gmail.com>

drw.c

diff --git a/drw.c b/drw.c
index a50c9ee0545db977ab4b9afbe49955cdddddbda4..2f3a5df25b01e6438d2531add938157cd1561d50 100644 (file)
--- a/drw.c
+++ b/drw.c
@@ -267,7 +267,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
        enum { nomatches_len = 64 };
        static struct { long codepoint[nomatches_len]; unsigned int idx; } nomatches;
 
-       if (!drw || (render && !drw->scheme) || !text || !drw->fonts)
+       if (!drw || (render && (!drw->scheme || !w)) || !text || !drw->fonts)
                return 0;
 
        if (!render) {