[wiki] [sites] [dwm][patch][colorschemes] Edit patch || Listeria monocytogenes

From: <git_AT_suckless.org>
Date: Tue, 16 Jul 2024 18:25:42 +0200

commit e0bae94eafe1db597e25acbbae9f7e6d2e642ec8
Author: Listeria monocytogenes <listeria_AT_disroot.org>
Date: Tue Jul 16 13:19:49 2024 -0300

    [dwm][patch][colorschemes] Edit patch
    
    use indices to avoid having `scheme` overflow the `schemes` array bounds
    which may lead to undefined behavior

diff --git a/dwm.suckless.org/patches/colorschemes/dwm-colorschemes-6.5.diff b/dwm.suckless.org/patches/colorschemes/dwm-colorschemes-6.5.diff
index 80669f77..f3b6658f 100644
--- a/dwm.suckless.org/patches/colorschemes/dwm-colorschemes-6.5.diff
+++ b/dwm.suckless.org/patches/colorschemes/dwm-colorschemes-6.5.diff
_AT_@ -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_AT_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
_AT_@ -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
 _AT_@ -59,7 +59,7 @@
_AT_@ -84,18 +84,22 @@ index f1d86b2..41b18a5 100644
          XDestroyWindow(dpy, wmcheckwin);
          drw_free(drw);
          XSync(dpy, False);
-_AT_@ -1536,10 +1537,21 @@ setmfact(const Arg *arg)
+_AT_@ -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();
 +}
 +
_AT_@ -107,7 +111,7 @@ index f1d86b2..41b18a5 100644
          XSetWindowAttributes wa;
          Atom utf8string;
          struct sigaction sa;
-_AT_@ -1584,9 +1596,12 @@ setup(void)
+_AT_@ -1584,9 +1600,12 @@ setup(void)
          cursor[CurResize] = drw_cur_create(drw, XC_sizing);
          cursor[CurMove] = drw_cur_create(drw, XC_fleur);
          /* init appearance */
Received on Tue Jul 16 2024 - 18:25:42 CEST

This archive was generated by hypermail 2.3.0 : Tue Jul 16 2024 - 18:36:51 CEST