* [PATCH 0/1] Replace strncpy w/ memcpy to avoid -Wstringop-truncation
@ 2019-03-23 10:43 Wesley Schwengle
2019-03-23 10:43 ` [PATCH] " Wesley Schwengle
2019-03-25 11:50 ` [PATCH 0/1] " Jun T
0 siblings, 2 replies; 3+ messages in thread
From: Wesley Schwengle @ 2019-03-23 10:43 UTC (permalink / raw)
To: zsh-workers; +Cc: Wesley Schwengle
From: Wesley Schwengle <wesley@schwengle.net>
Another warning that I saw when building from git on Debian with cc
8.3.0 was this one.
params.c: In function ‘assignstrvalue.part.16’:
params.c:2588:17: warning: ‘strncpy’ output truncated before terminating
nul copying as many bytes from a string as its length [-Wstringop-truncation]
strncpy(z + v->start, val, vlen);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
params.c:2571:20: note: length computed here
vlen = strlen(val);
^~~~~~~~~~~
In this case I replaces strncpy with memcpy().
Wesley Schwengle (1):
Replace strncpy w/ memcpy to avoid -Wstringop-truncation
Src/params.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--
2.21.0.196.g041f5ea1cf
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] Replace strncpy w/ memcpy to avoid -Wstringop-truncation
2019-03-23 10:43 [PATCH 0/1] Replace strncpy w/ memcpy to avoid -Wstringop-truncation Wesley Schwengle
@ 2019-03-23 10:43 ` Wesley Schwengle
2019-03-25 11:50 ` [PATCH 0/1] " Jun T
1 sibling, 0 replies; 3+ messages in thread
From: Wesley Schwengle @ 2019-03-23 10:43 UTC (permalink / raw)
To: zsh-workers; +Cc: Wesley Schwengle
From: Wesley Schwengle <wesley@schwengle.net>
Signed-off-by: Wesley Schwengle <wesley@schwengle.net>
---
Src/params.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Src/params.c b/Src/params.c
index 089a958ae..66e00e422 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -2585,7 +2585,7 @@ assignstrvalue(Value v, char *val, int flags)
Param pm = v->pm;
/* Size doesn't change, can limit actions to only
* overwriting bytes in already allocated string */
- strncpy(z + v->start, val, vlen);
+ memcpy(z + v->start, val, vlen);
/* Implement remainder of strsetfn */
if (!(pm->node.flags & PM_HASHELEM) &&
((pm->node.flags & PM_NAMEDDIR) ||
--
2.21.0.196.g041f5ea1cf
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 0/1] Replace strncpy w/ memcpy to avoid -Wstringop-truncation
2019-03-23 10:43 [PATCH 0/1] Replace strncpy w/ memcpy to avoid -Wstringop-truncation Wesley Schwengle
2019-03-23 10:43 ` [PATCH] " Wesley Schwengle
@ 2019-03-25 11:50 ` Jun T
1 sibling, 0 replies; 3+ messages in thread
From: Jun T @ 2019-03-25 11:50 UTC (permalink / raw)
To: zsh-workers
> 2019/03/23 19:43, Wesley Schwengle <wesleyschwengle@gmail.com> wrote:
>
> Another warning that I saw when building from git on Debian with cc
> 8.3.0 was this one.
>
> params.c: In function ‘assignstrvalue.part.16’:
> params.c:2588:17: warning: ‘strncpy’ output truncated before terminating
> nul copying as many bytes from a string as its length [-Wstringop-truncation]
> strncpy(z + v->start, val, vlen);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> params.c:2571:20: note: length computed here
> vlen = strlen(val);
> ^~~~~~~~~~~
>
> In this case I replaces strncpy with memcpy().
Thanks. I've pushed your patch.
The last null byte of val is never copied here so using memcpy()
is more appropriate, I think.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-03-25 11:51 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-23 10:43 [PATCH 0/1] Replace strncpy w/ memcpy to avoid -Wstringop-truncation Wesley Schwengle
2019-03-23 10:43 ` [PATCH] " Wesley Schwengle
2019-03-25 11:50 ` [PATCH 0/1] " Jun T
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).