Merge pull request #12860 from aabadie/pr/tools/ethos_fix_warning

tools/ethos: fix compilation warning in strncpy
This commit is contained in:
benpicco 2019-12-03 15:08:36 +01:00 committed by GitHub
commit 61353e04eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -156,7 +156,7 @@ typedef struct {
**************************************************************************/
int tun_alloc(char *dev, int flags) {
struct ifreq ifr;
struct ifreq ifr = { 0 };
int fd, err;
if( (fd = open("/dev/net/tun", O_RDWR)) < 0 ) {
@ -164,12 +164,10 @@ int tun_alloc(char *dev, int flags) {
return fd;
}
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = flags;
if (*dev) {
strncpy(ifr.ifr_name, dev, IFNAMSIZ);
strncpy(ifr.ifr_name, dev, IFNAMSIZ - 1);
}
if( (err = ioctl(fd, TUNSETIFF, (void *)&ifr)) < 0 ) {
@ -515,8 +513,8 @@ int main(int argc, char *argv[])
serial_option = argv[3];
}
char ifname[IFNAMSIZ];
strncpy(ifname, argv[1], IFNAMSIZ);
char ifname[IFNAMSIZ] = { 0 };
strncpy(ifname, argv[1], IFNAMSIZ - 1);
int tap_fd = tun_alloc(ifname, IFF_TAP | IFF_NO_PI);
if (tap_fd < 0) {