summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNRK <nrk@disroot.org>2022-09-01 23:51:43 +0600
committerrafa_99 <raroma09@gmail.com>2022-09-03 13:34:38 +0100
commitc69729f3396e5c7d3260944d451738616514cf4b (patch)
tree39b82f47bd040949b13ec8851f9e7a391b4f38b9
parentd53722bba369059c58fa771eaa95c4f95bfb7eba (diff)
tab-complete: figure out the size before copying
we already need to know the string length since `cursor` needs to be adjusted. so just calculate the length beforehand and use `memcpy` to copy exactly as much as needed (as opposed to `strncpy` which always writes `n` bytes).
-rw-r--r--dmenu.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/dmenu.c b/dmenu.c
index 289213e..4835c00 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -524,9 +524,9 @@ insert:
case XK_Tab:
if (!sel)
return;
- strncpy(text, sel->text, sizeof text - 1);
+ cursor = strnlen(sel->text, sizeof text - 1);
+ memcpy(text, sel->text, cursor);
text[sizeof text - 1] = '\0';
- cursor = strlen(text);
match();
break;
}