diff options
author | 2022-05-11 17:18:39 +0200 | |
---|---|---|
committer | 2022-05-11 11:47:49 -0400 | |
commit | 1e9be019b2af7ad4aca66ba6460f56453829485d (patch) | |
tree | cb57946ad417d2ce7f59349f5a0ba81aecd989a8 /sway | |
parent | config: Remove unused mouse binding structure (diff) | |
download | sway-1e9be019b2af7ad4aca66ba6460f56453829485d.tar.gz sway-1e9be019b2af7ad4aca66ba6460f56453829485d.tar.zst sway-1e9be019b2af7ad4aca66ba6460f56453829485d.zip |
Replace strncpy with memcpy
strncpy is useless here, is dangerous because it doesn't guarantee
that the string is NUL-terminated and causes the following warning:
../sway/criteria.c: In function ‘criteria_parse’:
../sway/criteria.c:712:25: error: ‘strncpy’ destination unchanged after copying no bytes [-Werror=stringop-truncation]
712 | strncpy(value, valuestart, head - valuestart);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Diffstat (limited to 'sway')
-rw-r--r-- | sway/criteria.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/sway/criteria.c b/sway/criteria.c index 94751c5f..97cf667e 100644 --- a/sway/criteria.c +++ b/sway/criteria.c | |||
@@ -682,7 +682,7 @@ struct criteria *criteria_parse(char *raw, char **error_arg) { | |||
682 | } | 682 | } |
683 | name = calloc(head - namestart + 1, 1); | 683 | name = calloc(head - namestart + 1, 1); |
684 | if (head != namestart) { | 684 | if (head != namestart) { |
685 | strncpy(name, namestart, head - namestart); | 685 | memcpy(name, namestart, head - namestart); |
686 | } | 686 | } |
687 | // Parse token value | 687 | // Parse token value |
688 | skip_spaces(&head); | 688 | skip_spaces(&head); |
@@ -709,7 +709,7 @@ struct criteria *criteria_parse(char *raw, char **error_arg) { | |||
709 | } | 709 | } |
710 | } | 710 | } |
711 | value = calloc(head - valuestart + 1, 1); | 711 | value = calloc(head - valuestart + 1, 1); |
712 | strncpy(value, valuestart, head - valuestart); | 712 | memcpy(value, valuestart, head - valuestart); |
713 | if (in_quotes) { | 713 | if (in_quotes) { |
714 | ++head; | 714 | ++head; |
715 | in_quotes = false; | 715 | in_quotes = false; |
@@ -740,7 +740,7 @@ struct criteria *criteria_parse(char *raw, char **error_arg) { | |||
740 | ++head; | 740 | ++head; |
741 | int len = head - raw; | 741 | int len = head - raw; |
742 | criteria->raw = calloc(len + 1, 1); | 742 | criteria->raw = calloc(len + 1, 1); |
743 | strncpy(criteria->raw, raw, len); | 743 | memcpy(criteria->raw, raw, len); |
744 | return criteria; | 744 | return criteria; |
745 | 745 | ||
746 | cleanup: | 746 | cleanup: |