@@ -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;
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(-)