diff mbox series

v4l-utils: libdvbv5: fix broken my_strlcpy calls

Message ID b18b9189-3621-16d0-4866-dccff52c453a@xs4all.nl (mailing list archive)
State New, archived
Headers show
Series v4l-utils: libdvbv5: fix broken my_strlcpy calls | expand

Commit Message

Hans Verkuil June 12, 2021, 9:47 a.m. UTC
sizeof(*msg->cmd) should have been sizeof(msg->cmd).

Also, call strncpy with siz - 1 instead of siz to avoid this
compiler warning:

  CC       libdvbv5_la-dvb-dev-remote.lo
In function ‘my_strlcpy’,
    inlined from ‘send_buf.isra.0.constprop’ at dvb-dev-remote.c:350:2:
dvb-dev-remote.c:121:7: warning: ‘strncpy’ output truncated copying 1 byte from a string of length 12 [-Wstringop-truncation]
  121 |  rc = strncpy(dst, src, siz);
      |       ^~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 lib/libdvbv5/dvb-dev-remote.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/lib/libdvbv5/dvb-dev-remote.c b/lib/libdvbv5/dvb-dev-remote.c
index fa551b82..3ef9d67c 100644
--- a/lib/libdvbv5/dvb-dev-remote.c
+++ b/lib/libdvbv5/dvb-dev-remote.c
@@ -118,7 +118,7 @@  static char *my_strlcpy(char *dst, const char *src, size_t siz)
 {
 	char *rc;

-	rc = strncpy(dst, src, siz);
+	rc = strncpy(dst, src, siz - 1);
 	dst[siz - 1] = '\0';

 	return rc;
@@ -251,7 +251,7 @@  static struct queued_msg *send_fmt(struct dvb_device_priv *dvb, int fd,

 	pthread_mutex_init(&msg->lock, NULL);
 	pthread_cond_init(&msg->cond, NULL);
-	my_strlcpy(msg->cmd, cmd, sizeof(*msg->cmd));
+	my_strlcpy(msg->cmd, cmd, sizeof(msg->cmd));

 	pthread_mutex_lock(&priv->lock_io);
 	msg->seq = ++priv->seq;
@@ -347,7 +347,7 @@  static struct queued_msg *send_buf(struct dvb_device_priv *dvb, int fd,

 	pthread_mutex_init(&msg->lock, NULL);
 	pthread_cond_init(&msg->cond, NULL);
-	my_strlcpy(msg->cmd, cmd, sizeof(*msg->cmd));
+	my_strlcpy(msg->cmd, cmd, sizeof(msg->cmd));

 	pthread_mutex_lock(&priv->lock_io);
 	msg->seq = ++priv->seq;