commit e0bae94eafe1db597e25acbbae9f7e6d2e642ec8
parent 886235a1ed3912b74b69f36ed1e7117847131b08
Author: Listeria monocytogenes <listeria@disroot.org>
Date: Tue, 16 Jul 2024 13:19:49 -0300
[dwm][patch][colorschemes] Edit patch
use indices to avoid having `scheme` overflow the `schemes` array bounds
which may lead to undefined behavior
Diffstat:
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/dwm.suckless.org/patches/colorschemes/dwm-colorschemes-6.5.diff b/dwm.suckless.org/patches/colorschemes/dwm-colorschemes-6.5.diff
@@ -1,12 +1,12 @@
-From 4a8fb76f746eec25b965f8615f1a0bf6bd63fc17 Mon Sep 17 00:00:00 2001
+From a9dc99543fe07801587ed1b412cd97b5da01474f Mon Sep 17 00:00:00 2001
From: Listeria monocytogenes <listeria@disroot.org>
Date: Wed, 26 Jun 2024 11:49:20 -0300
Subject: [PATCH] add setscheme() to cycle between colorschemes
---
config.def.h | 15 +++++++++++----
- dwm.c | 33 ++++++++++++++++++++++++---------
- 2 files changed, 35 insertions(+), 13 deletions(-)
+ dwm.c | 37 ++++++++++++++++++++++++++++---------
+ 2 files changed, 39 insertions(+), 13 deletions(-)
diff --git a/config.def.h b/config.def.h
index 9efa774..f87f707 100644
@@ -42,7 +42,7 @@ index 9efa774..f87f707 100644
TAGKEYS( XK_2, 1)
TAGKEYS( XK_3, 2)
diff --git a/dwm.c b/dwm.c
-index f1d86b2..41b18a5 100644
+index f1d86b2..1ac8e05 100644
--- a/dwm.c
+++ b/dwm.c
@@ -59,7 +59,7 @@
@@ -84,18 +84,22 @@ index f1d86b2..41b18a5 100644
XDestroyWindow(dpy, wmcheckwin);
drw_free(drw);
XSync(dpy, False);
-@@ -1536,10 +1537,21 @@ setmfact(const Arg *arg)
+@@ -1536,10 +1537,25 @@ setmfact(const Arg *arg)
arrange(selmon);
}
+void
+setscheme(const Arg *arg)
+{
-+ scheme += arg->i * SchemeN;
-+ if (scheme < schemes)
-+ scheme = schemes + (LENGTH(colors) - 1) * SchemeN;
-+ else if (scheme >= schemes + LENGTH(colors) * SchemeN)
-+ scheme = schemes;
++ ptrdiff_t si = (scheme - schemes) + arg->i * SchemeN;
++
++ /* wrap around, won't work if (abs(arg->i) > LENGTH(colors)) */
++ if (si < 0)
++ si += LENGTH(colors) * SchemeN;
++ else if (si >= LENGTH(colors) * SchemeN)
++ si -= LENGTH(colors) * SchemeN;
++
++ scheme = &schemes[si];
+ drawbars();
+}
+
@@ -107,7 +111,7 @@ index f1d86b2..41b18a5 100644
XSetWindowAttributes wa;
Atom utf8string;
struct sigaction sa;
-@@ -1584,9 +1596,12 @@ setup(void)
+@@ -1584,9 +1600,12 @@ setup(void)
cursor[CurResize] = drw_cur_create(drw, XC_sizing);
cursor[CurMove] = drw_cur_create(drw, XC_fleur);
/* init appearance */