diff options
author | Sergei Trofimovich <slyich@gmail.com> | 2023-11-28 22:17:21 +0000 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2023-11-29 10:30:17 +0100 |
commit | 2cd73a33c26ea6510a2f50359b1c550cd9b4fead (patch) | |
tree | acd0e877f677059e33ee3d153c1415a59e094e94 | |
parent | bc7d15d64da1d8b97d52928b8f9ce5688c8dbdd0 (diff) |
sway/config.c: use `memcpy()` for known buffer size
`gcc-14` added a new warning around dangerous use of `strncpy()` withi
known overflow:
../sway/config.c: In function 'do_var_replacement':
../sway/config.c:983:33: error: '__builtin___strncpy_chk' specified bound depends on the length of the source argument [-Werror=stringop-truncation]
983 | strncpy(newptr, var->value, vvlen);
| ^
../sway/config.c:971:45: note: length computed here
971 | int vvlen = strlen(var->value);
| ^~~~~~~~~~~~~~~~~~
It's a bit fishy to rely on truncating behaviour of `strncpy()`. The
change uses `memcpy()` as more explicit way to express copy of `vvlen`
bytes.
-rw-r--r-- | sway/config.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/sway/config.c b/sway/config.c index 8c8c148d..4b51dc73 100644 --- a/sway/config.c +++ b/sway/config.c @@ -975,7 +975,7 @@ char *do_var_replacement(char *str) { int offset = find - str; strncpy(newptr, str, offset); newptr += offset; - strncpy(newptr, var->value, vvlen); + memcpy(newptr, var->value, vvlen); newptr += vvlen; strcpy(newptr, find + vnlen); free(str); |