diff options
author | Jeff Long <willcode4@gmail.com> | 2021-02-11 07:30:08 -0500 |
---|---|---|
committer | Martin Braun <martin@gnuradio.org> | 2021-02-11 07:12:20 -0800 |
commit | ce88621d8e3e45cb808227d417f1e9e839a15453 (patch) | |
tree | c6394e0d78a7f9332b17412b342aa586ce4b5ec2 /gr-blocks/lib | |
parent | 7e77ea24382ce2b2c14872653037603e391f2a41 (diff) |
gr-blocks: tuntap_pdu: change char array size to fix warning on strncpy
Signed-off-by: Jeff Long <willcode4@gmail.com>
Diffstat (limited to 'gr-blocks/lib')
-rw-r--r-- | gr-blocks/lib/tuntap_pdu_impl.cc | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/gr-blocks/lib/tuntap_pdu_impl.cc b/gr-blocks/lib/tuntap_pdu_impl.cc index 7d85e12db8..048c33c392 100644 --- a/gr-blocks/lib/tuntap_pdu_impl.cc +++ b/gr-blocks/lib/tuntap_pdu_impl.cc @@ -47,9 +47,10 @@ tuntap_pdu_impl::tuntap_pdu_impl(std::string dev, int MTU, bool istunflag) d_istunflag(istunflag) { // make the tuntap - char dev_cstr[1024]; - memset(dev_cstr, 0x00, 1024); - strncpy(dev_cstr, dev.c_str(), std::min(sizeof(dev_cstr) - 1, dev.size())); + char dev_cstr[IFNAMSIZ]; + memset(dev_cstr, 0x00, IFNAMSIZ); + strncpy(dev_cstr, dev.c_str(), IFNAMSIZ); + dev_cstr[IFNAMSIZ - 1] = '\0'; bool istun = d_istunflag; if (istun) { @@ -150,7 +151,8 @@ int tuntap_pdu_impl::set_mtu(const char* dev, int MTU) /* preparation of the struct ifr, of type "struct ifreq" */ memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, dev, IFNAMSIZ - 1); + strncpy(ifr.ifr_name, dev, IFNAMSIZ); + ifr.ifr_name[IFNAMSIZ - 1] = '\0'; ifr.ifr_addr.sa_family = AF_INET; /* address family */ ifr.ifr_mtu = MTU; |