mirror of
https://github.com/swaywm/sway.git
synced 2024-11-25 17:31:28 +00:00
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.
This commit is contained in:
parent
bc7d15d64d
commit
2cd73a33c2
|
@ -975,7 +975,7 @@ char *do_var_replacement(char *str) {
|
||||||
int offset = find - str;
|
int offset = find - str;
|
||||||
strncpy(newptr, str, offset);
|
strncpy(newptr, str, offset);
|
||||||
newptr += offset;
|
newptr += offset;
|
||||||
strncpy(newptr, var->value, vvlen);
|
memcpy(newptr, var->value, vvlen);
|
||||||
newptr += vvlen;
|
newptr += vvlen;
|
||||||
strcpy(newptr, find + vnlen);
|
strcpy(newptr, find + vnlen);
|
||||||
free(str);
|
free(str);
|
||||||
|
|
Loading…
Reference in a new issue