[virt-tools-list] [virt-viewer PATCH v2 2/3] Fix warning about missing nul terminator with strncpy
Christophe Fergeau
cfergeau at redhat.com
Mon Mar 4 12:43:32 UTC 2019
Reviewed-by: Christophe Fergeau <cfergeau at redhat.com>
On Tue, Feb 19, 2019 at 03:00:10PM +0000, Daniel P. Berrangé wrote:
> We're intentionally not copying the nul terminator, but gcc rightly
> worries that this could be a coding mistake
>
> windows-cmdline-wrapper.c: In function 'main':
> windows-cmdline-wrapper.c:65:9: warning: 'strncpy' output truncated before terminating nul copying 3 bytes from a string of the same length [-Wstringop-truncation]
> strncpy(name + len - 3, "exe", 3);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> Use memcpy() to make it clear we don't care about the nul terminator in
> the data we're copying.
>
> Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
> ---
> src/windows-cmdline-wrapper.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/windows-cmdline-wrapper.c b/src/windows-cmdline-wrapper.c
> index 704e2d7..7299ab2 100644
> --- a/src/windows-cmdline-wrapper.c
> +++ b/src/windows-cmdline-wrapper.c
> @@ -62,7 +62,7 @@ int main(int argc, char *argv[])
> // We expect our helper to end with .com
> assert(strncmp(name + len - 3, "com", 4) == 0);
> // replace .com with .exe
> - strncpy(name + len - 3, "exe", 3);
> + memcpy(name + len - 3, "exe", 3);
> }
>
> si.cb = sizeof(si);
> --
> 2.20.1
>
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20190304/7150f02d/attachment.sig>
More information about the virt-tools-list
mailing list