diff options
author | NRK <nrk@disroot.org> | 2022-09-01 23:51:43 +0600 |
---|---|---|
committer | rafa_99 <raroma09@gmail.com> | 2022-09-03 13:34:38 +0100 |
commit | c69729f3396e5c7d3260944d451738616514cf4b (patch) | |
tree | 39b82f47bd040949b13ec8851f9e7a391b4f38b9 | |
parent | d53722bba369059c58fa771eaa95c4f95bfb7eba (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.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -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; } |