aboutsummaryrefslogtreecommitdiff
path: root/dwm.c
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2026-10-30 11:31:16 +0100
committerHiltjo Posthuma <hiltjo@codemadness.org>2026-10-30 11:31:16 +0100
commit1563572d1de565ebbe8b8d4eaf9f538f9b68f355 (patch)
tree0a01bf7a8bec211c4c7354ef43f77205f93e248e /dwm.c
parentf08763b74e32d83dd5d706ce2090b235ed518a89 (diff)
replace strncpy with snprintf()HEADmaster
Using snprintf() like this is similar to using strlcpy(). Truncation is silently ignored, which is fine here. strncpy also pads the buffer with zeroes, which is not necesary here.
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/dwm.c b/dwm.c
index 35cce9a..604def2 100644
--- a/dwm.c
+++ b/dwm.c
@@ -395,8 +395,7 @@ arrange(Monitor *m)
void
arrangemon(Monitor *m)
{
- strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof(m->ltsymbol) - 1);
- m->ltsymbol[sizeof(m->ltsymbol) - 1] = '\0';
+ snprintf(m->ltsymbol, sizeof(m->ltsymbol), "%s", m->lt[m->sellt]->symbol);
if (m->lt[m->sellt]->arrange)
m->lt[m->sellt]->arrange(m);
}
@@ -646,8 +645,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) - 1);
- m->ltsymbol[sizeof(m->ltsymbol) - 1] = '\0';
+ snprintf(m->ltsymbol, sizeof(m->ltsymbol), "%s", layouts[0].symbol);
return m;
}
@@ -923,13 +921,12 @@ gettextprop(Window w, Atom atom, char *text, unsigned int size)
if (!XGetTextProperty(dpy, w, &name, atom) || !name.nitems)
return 0;
if (name.encoding == XA_STRING) {
- strncpy(text, (char *)name.value, size - 1);
+ snprintf(text, size, "%s", (char *)name.value);
} else if (XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success) {
if (n > 0 && *list)
- strncpy(text, *list, size - 1);
+ snprintf(text, size, "%s", *list);
XFreeStringList(list);
}
- text[size - 1] = '\0';
XFree(name.value);
return 1;
}
@@ -1520,8 +1517,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) - 1);
- selmon->ltsymbol[sizeof(selmon->ltsymbol) - 1] = '\0';
+ snprintf(selmon->ltsymbol, sizeof(selmon->ltsymbol), "%s", selmon->lt[selmon->sellt]->symbol);
if (selmon->sel)
arrange(selmon);
else