All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] v4l-utils: libdvbv5: fix broken my_strlcpy calls
@ 2021-06-12  9:47 Hans Verkuil
  0 siblings, 0 replies; only message in thread
From: Hans Verkuil @ 2021-06-12  9:47 UTC (permalink / raw)
  To: Linux Media Mailing List; +Cc: Mauro Carvalho Chehab

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


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-12  9:47 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-12  9:47 [PATCH] v4l-utils: libdvbv5: fix broken my_strlcpy calls Hans Verkuil

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.