[hackers] [dwm][PATCH] Add ' - 1' to size arg to avoid warnings with -O2

From: sulevedant=gmail.com <Vedant>
Date: Tue, 27 Oct 2026 23:10:29 +0000

On Gentoo I use -O2 to compile packages, which causes the compiler to
enable some additional warnings, such as when the size argument of
strncpy is equal to the size of the destination buffer. This patch
avoids those warnings and makes strncpy calls more consistent with those
on lines 921 and 923.

Alternatively, we could replace all of these with snprintf.
---
 dwm.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/dwm.c b/dwm.c
index ab3a84c..96fda94 100644
--- a/dwm.c
+++ b/dwm.c
_at_@ -395,7 +395,7 @@ arrange(Monitor *m)
 void
 arrangemon(Monitor *m)
 {
-	strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol);
+	strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol - 1);
 	if (m->lt[m->sellt]->arrange)
 		m->lt[m->sellt]->arrange(m);
 }
_at_@ -642,7 +642,7 @@ createmon(void)
 	m->topbar = topbar;
 	m->lt[0] = &layouts[0];
 	m->lt[1] = &layouts[1 % LENGTH(layouts)];
-	strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
+	strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol - 1);
 	return m;
 }
 
_at_@ -1514,7 +1514,7 @@ setlayout(const Arg *arg)
 		selmon->sellt ^= 1;
 	if (arg && arg->v)
 		selmon->lt[selmon->sellt] = (Layout *)arg->v;
-	strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
+	strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol - 1);
 	if (selmon->sel)
 		arrange(selmon);
 	else
-- 
2.55.0
Received on Wed Oct 28 2026 - 00:10:29 CET

This archive was generated by hypermail 2.3.0 : Wed Oct 28 2026 - 10:48:39 CET