From b99dcd44b7fd7049cc90ea220206931a184f68e1 Mon Sep 17 00:00:00 2001 From: Liming Sun Date: Tue, 14 Apr 2020 15:12:17 -0400 Subject: [PATCH] Fix several compiling warnings Signed-off-by: Liming Sun --- src/rshim_net.c | 8 ++++---- src/rshim_pcie.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/rshim_net.c b/src/rshim_net.c index 626d556..6f984ba 100644 --- a/src/rshim_net.c +++ b/src/rshim_net.c @@ -68,7 +68,7 @@ static int rshim_if_open(char *ifname, int index) memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TAP | IFF_NO_PI; - strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name) - 1); + snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", ifname); rc = ioctl(fd, TUNSETIFF, (void *) &ifr); if (rc < 0) { @@ -144,7 +144,7 @@ static int rshim_if_open(char *ifname, int index) char temp[sizeof(ifr.ifr_name)]; memcpy(temp, ifr.ifr_name, sizeof(temp)); - strncpy(ifr.ifr_name, ifname, sizeof(temp)); + snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", ifname); /* cleanup old device */ if (ioctl(s, SIOCIFDESTROY, &ifr) < 0) { @@ -154,7 +154,7 @@ static int rshim_if_open(char *ifname, int index) return -1; } - strncpy(ifr.ifr_name, temp, sizeof(temp)); + snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", temp); /* try to rename device again */ if (ioctl(s, SIOCSIFNAME, &ifr) < 0) { @@ -165,7 +165,7 @@ static int rshim_if_open(char *ifname, int index) } } - strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", ifname); ifr.ifr_mtu = ETH_PKT_SIZE; if (ioctl(s, SIOCSIFMTU, &ifr) < 0) { diff --git a/src/rshim_pcie.c b/src/rshim_pcie.c index 065d067..c65f2f5 100644 --- a/src/rshim_pcie.c +++ b/src/rshim_pcie.c @@ -300,7 +300,7 @@ static int rshim_pcie_probe(struct pci_dev *pci_dev) #ifdef __linux__ char path[256]; #endif - int ret; + int ret = 0; snprintf(dev_name, sizeof(dev_name) - 1, "pcie-%02x:%02x.%x", pci_dev->bus, pci_dev->dev, pci_dev->func); @@ -445,7 +445,7 @@ int rshim_pcie_enable(void *dev) #ifdef __linux__ struct pci_dev *pci_dev = (struct pci_dev *)dev; char name[256]; - int fd, rc; + int fd, rc = 0; snprintf(name, sizeof(name), "%s/%04x:%02x:%02x.%1u/enable", SYS_BUS_PCI, pci_dev->domain, pci_dev->bus,