* [PATCH] TTY: isdn: Replace strncpy with memcpy
@ 2018-07-01 20:57 Guenter Roeck
2018-07-02 13:43 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Guenter Roeck @ 2018-07-01 20:57 UTC (permalink / raw)
To: Karsten Keil; +Cc: Kees Cook, linux-kernel, netdev, Guenter Roeck
gcc 8.1.0 complains:
drivers/isdn/i4l/isdn_tty.c: In function 'isdn_tty_suspend.isra.1':
drivers/isdn/i4l/isdn_tty.c:790:3: warning:
'strncpy' output truncated before terminating nul copying
as many bytes from a string as its length
drivers/isdn/i4l/isdn_tty.c:778:6: note: length computed here
drivers/isdn/i4l/isdn_tty.c: In function 'isdn_tty_resume':
drivers/isdn/i4l/isdn_tty.c:880:3: warning:
'strncpy' output truncated before terminating nul copying
as many bytes from a string as its length
drivers/isdn/i4l/isdn_tty.c:817:6: note: length computed here
Using strncpy() is indeed less than perfect since the length of data to
be copied has already been determined with strlen(). Replace strncpy()
with memcpy() to address the warning and optimize the code a little.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/isdn/i4l/isdn_tty.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
index 960f26348bb5..b730037a0e2d 100644
--- a/drivers/isdn/i4l/isdn_tty.c
+++ b/drivers/isdn/i4l/isdn_tty.c
@@ -787,7 +787,7 @@ isdn_tty_suspend(char *id, modem_info *info, atemu *m)
cmd.parm.cmsg.para[3] = 4; /* 16 bit 0x0004 Suspend */
cmd.parm.cmsg.para[4] = 0;
cmd.parm.cmsg.para[5] = l;
- strncpy(&cmd.parm.cmsg.para[6], id, l);
+ memcpy(&cmd.parm.cmsg.para[6], id, l);
cmd.command = CAPI_PUT_MESSAGE;
cmd.driver = info->isdn_driver;
cmd.arg = info->isdn_channel;
@@ -877,7 +877,7 @@ isdn_tty_resume(char *id, modem_info *info, atemu *m)
cmd.parm.cmsg.para[3] = 5; /* 16 bit 0x0005 Resume */
cmd.parm.cmsg.para[4] = 0;
cmd.parm.cmsg.para[5] = l;
- strncpy(&cmd.parm.cmsg.para[6], id, l);
+ memcpy(&cmd.parm.cmsg.para[6], id, l);
cmd.command = CAPI_PUT_MESSAGE;
info->dialing = 1;
// strcpy(dev->num[i], n);
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] TTY: isdn: Replace strncpy with memcpy
2018-07-01 20:57 [PATCH] TTY: isdn: Replace strncpy with memcpy Guenter Roeck
@ 2018-07-02 13:43 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2018-07-02 13:43 UTC (permalink / raw)
To: linux; +Cc: isdn, keescook, linux-kernel, netdev
From: Guenter Roeck <linux@roeck-us.net>
Date: Sun, 1 Jul 2018 13:57:38 -0700
> gcc 8.1.0 complains:
>
> drivers/isdn/i4l/isdn_tty.c: In function 'isdn_tty_suspend.isra.1':
> drivers/isdn/i4l/isdn_tty.c:790:3: warning:
> 'strncpy' output truncated before terminating nul copying
> as many bytes from a string as its length
> drivers/isdn/i4l/isdn_tty.c:778:6: note: length computed here
>
> drivers/isdn/i4l/isdn_tty.c: In function 'isdn_tty_resume':
> drivers/isdn/i4l/isdn_tty.c:880:3: warning:
> 'strncpy' output truncated before terminating nul copying
> as many bytes from a string as its length
> drivers/isdn/i4l/isdn_tty.c:817:6: note: length computed here
>
> Using strncpy() is indeed less than perfect since the length of data to
> be copied has already been determined with strlen(). Replace strncpy()
> with memcpy() to address the warning and optimize the code a little.
>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Applied.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-07-02 13:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-01 20:57 [PATCH] TTY: isdn: Replace strncpy with memcpy Guenter Roeck
2018-07-02 13:43 ` David Miller
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.