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
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
> 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.