[PATCH kvmtool v2 2/3] virtio: fix warning on strncpy

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

 



GCC 8.2 gives this warning:

virtio/net.c: In function ‘virtio_net__tap_init’:
virtio/net.c:336:47: error: argument to ‘sizeof’ in ‘strncpy’ call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]
   strncpy(ifr.ifr_name, ndev->tap_name, sizeof(ndev->tap_name));
                                               ^
virtio/net.c:348:47: error: argument to ‘sizeof’ in ‘strncpy’ call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]
   strncpy(ifr.ifr_name, ndev->tap_name, sizeof(ndev->tap_name));
                                               ^

Fix it by using sizeof of destination instead, even if they're the same
size in this case.

Signed-off-by: Anisse Astier <aastier@xxxxxxxxxx>
---
 virtio/net.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/virtio/net.c b/virtio/net.c
index a05f4cd..35ff2e9 100644
--- a/virtio/net.c
+++ b/virtio/net.c
@@ -331,7 +331,7 @@ static bool virtio_net__tap_init(struct net_dev *ndev)
 			goto fail;
 	} else if (!skipconf) {
 		memset(&ifr, 0, sizeof(ifr));
-		strncpy(ifr.ifr_name, ndev->tap_name, sizeof(ndev->tap_name));
+		strncpy(ifr.ifr_name, ndev->tap_name, sizeof(ifr.ifr_name));
 		sin.sin_addr.s_addr = inet_addr(params->host_ip);
 		memcpy(&(ifr.ifr_addr), &sin, sizeof(ifr.ifr_addr));
 		ifr.ifr_addr.sa_family = AF_INET;
@@ -343,7 +343,7 @@ static bool virtio_net__tap_init(struct net_dev *ndev)
 
 	if (!skipconf) {
 		memset(&ifr, 0, sizeof(ifr));
-		strncpy(ifr.ifr_name, ndev->tap_name, sizeof(ndev->tap_name));
+		strncpy(ifr.ifr_name, ndev->tap_name, sizeof(ifr.ifr_name));
 		ioctl(sock, SIOCGIFFLAGS, &ifr);
 		ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
 		if (ioctl(sock, SIOCSIFFLAGS, &ifr) < 0)
@@ -372,7 +372,7 @@ static void virtio_net__tap_exit(struct net_dev *ndev)
 		return;
 
 	sock = socket(AF_INET, SOCK_STREAM, 0);
-	strncpy(ifr.ifr_name, ndev->tap_name, sizeof(ndev->tap_name));
+	strncpy(ifr.ifr_name, ndev->tap_name, sizeof(ifr.ifr_name));
 	ioctl(sock, SIOCGIFFLAGS, &ifr);
 	ifr.ifr_flags &= ~(IFF_UP | IFF_RUNNING);
 	if (ioctl(sock, SIOCGIFFLAGS, &ifr) < 0)
-- 
2.19.1




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux