[PATCH] v4l-utils: libdvbv5: fix broken my_strlcpy calls

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 lib/libdvbv5/dvb-dev-remote.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

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;
-- 
2.24.0




[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux