[wiki] [sites] [dmenu][patch][numbers] update to fix segfault in some conditions || Ehsan Ghorbannezhad
commit 98926264b1507784b5e2af41890e26db0e28c1dd
Author: Ehsan Ghorbannezhad <ehsan_AT_disroot.org>
Date: Thu May 12 23:12:45 2022 +0430
[dmenu][patch][numbers] update to fix segfault in some conditions
diff --git a/tools.suckless.org/dmenu/patches/numbers/dmenu-numbers-20220512-28fb3e2.diff b/tools.suckless.org/dmenu/patches/numbers/dmenu-numbers-20220512-28fb3e2.diff
new file mode 100644
index 00000000..9a0fc3c6
--- /dev/null
+++ b/tools.suckless.org/dmenu/patches/numbers/dmenu-numbers-20220512-28fb3e2.diff
_AT_@ -0,0 +1,89 @@
+From c4cd209c2e322563750d09a3b64194d11cc12a10 Mon Sep 17 00:00:00 2001
+From: Ehsan Ghorbannezhad <ehsan_AT_disroot.org>
+Date: Thu, 12 May 2022 22:32:47 +0430
+Subject: [PATCH] the numbers patch, updated to fix segfault in some conditions
+
+---
+ dmenu.c | 27 ++++++++++++++++++++++++---
+ 1 file changed, 24 insertions(+), 3 deletions(-)
+
+diff --git a/dmenu.c b/dmenu.c
+index 571bc35..70004e7 100644
+--- a/dmenu.c
++++ b/dmenu.c
+_AT_@ -24,6 +24,8 @@
+ * MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org)))
+ #define LENGTH(X) (sizeof X / sizeof X[0])
+ #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
++#define NUMBERSMAXDIGITS 100
++#define NUMBERSBUFSIZE (NUMBERSMAXDIGITS * 2) + 1
+
+ /* enums */
+ enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
+_AT_@ -34,6 +36,7 @@ struct item {
+ int out;
+ };
+
++static char numbers[NUMBERSBUFSIZE] = "";
+ static char text[BUFSIZ] = "";
+ static char *embed;
+ static int bh, mw, mh;
+_AT_@ -86,7 +89,7 @@ calcoffsets(void)
+ if (lines > 0)
+ n = lines * bh;
+ else
+- n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">"));
++ n = mw - (promptw + inputw + TEXTW("<") + TEXTW(">") + TEXTW(numbers));
+ /* calculate which items will begin the next page and previous page */
+ for (i = 0, next = curr; next; next = next->right)
+ if ((i += (lines > 0) ? bh : textw_clamp(next->text, n)) > n)
+_AT_@ -143,6 +146,21 @@ drawitem(struct item *item, int x, int y, int w)
+ return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
+ }
+
++static void
++recalculatenumbers()
++{
++ unsigned int numer = 0, denom = 0;
++ struct item *item;
++ if (matchend) {
++ numer++;
++ for (item = matchend; item && item->left; item = item->left)
++ numer++;
++ }
++ for (item = items; item && item->text; item++)
++ denom++;
++ snprintf(numbers, NUMBERSBUFSIZE, "%d/%d", numer, denom);
++}
++
+ static void
+ drawmenu(void)
+ {
+_AT_@ -168,6 +186,7 @@ drawmenu(void)
+ drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
+ }
+
++ recalculatenumbers();
+ if (lines > 0) {
+ /* draw vertical list */
+ for (item = curr; item != next; item = item->right)
+_AT_@ -182,13 +201,15 @@ drawmenu(void)
+ }
+ x += w;
+ for (item = curr; item != next; item = item->right)
+- x = drawitem(item, x, 0, textw_clamp(item->text, mw - x - TEXTW(">")));
++ x = drawitem(item, x, 0, textw_clamp(item->text, mw - x - TEXTW(">") - TEXTW(numbers)));
+ if (next) {
+ w = TEXTW(">");
+ drw_setscheme(drw, scheme[SchemeNorm]);
+- drw_text(drw, mw - w, 0, w, bh, lrpad / 2, ">", 0);
++ drw_text(drw, mw - w - TEXTW(numbers), 0, w, bh, lrpad / 2, ">", 0);
+ }
+ }
++ drw_setscheme(drw, scheme[SchemeNorm]);
++ drw_text(drw, mw - TEXTW(numbers), 0, TEXTW(numbers), bh, lrpad / 2, numbers, 0);
+ drw_map(drw, win, 0, 0, mw, mh);
+ }
+
+--
+2.36.1
diff --git a/tools.suckless.org/dmenu/patches/numbers/index.md b/tools.suckless.org/dmenu/patches/numbers/index.md
index 455e4f50..3294f609 100644
--- a/tools.suckless.org/dmenu/patches/numbers/index.md
+++ b/tools.suckless.org/dmenu/patches/numbers/index.md
_AT_@ -7,8 +7,10 @@ corner of dmenu.
Download
--------
+* [dmenu-numbers-20220512-28fb3e2.diff](dmenu-numbers-20220512-28fb3e2.diff)
* [dmenu-numbers-4.9.diff](dmenu-numbers-4.9.diff)
-Author
-------
+Authors
+-------
* Miles Alan <m_AT_milesalan.com>
+* Ehsan Ghorbannezhad <ehsan_AT_disroot.org> (bugfixes)
Received on Thu May 12 2022 - 20:46:23 CEST
This archive was generated by hypermail 2.3.0
: Thu May 12 2022 - 20:48:45 CEST