summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Müller <mmueller@gnuradio.org>2021-08-16 19:58:08 +0200
committerMartin Braun <martin@gnuradio.org>2021-09-07 07:35:58 -0700
commit4c6ae3a386ec19698a8c01144c4e8a52fc113404 (patch)
tree813dce8f4f70deb15d1634e2cedea1f9e3cd9f04
parent0a4225dc9dd9e4d3c5ad58d40570d40d59f5670f (diff)
network: tuntap knows what it's doing when it uses strncpy, suppress warning
Signed-off-by: Marcus Müller <mmueller@gnuradio.org>
-rw-r--r--gr-network/lib/tuntap_pdu_impl.cc17
1 files changed, 14 insertions, 3 deletions
diff --git a/gr-network/lib/tuntap_pdu_impl.cc b/gr-network/lib/tuntap_pdu_impl.cc
index a1f5a01174..ab80e03b65 100644
--- a/gr-network/lib/tuntap_pdu_impl.cc
+++ b/gr-network/lib/tuntap_pdu_impl.cc
@@ -1,6 +1,7 @@
/* -*- c++ -*- */
/*
* Copyright 2013 Free Software Foundation, Inc.
+ * Copyright 2021 Marcus Müller
*
* This file is part of GNU Radio
*
@@ -52,14 +53,23 @@ tuntap_pdu_impl::tuntap_pdu_impl(std::string dev, int MTU, bool istunflag)
strncpy(dev_cstr, dev.c_str(), IFNAMSIZ);
dev_cstr[IFNAMSIZ - 1] = '\0';
-
bool istun = d_istunflag;
+
+#if defined(__GNUG__) && !defined(__clang__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-truncation"
+#endif
+
if (istun) {
d_fd = tun_alloc(dev_cstr, (IFF_TUN | IFF_NO_PI));
} else {
d_fd = tun_alloc(dev_cstr, (IFF_TAP | IFF_NO_PI));
}
+#if defined(__GNUG__) && !defined(__clang__)
+#pragma GCC diagnostic pop
+#endif
+
if (d_fd <= 0)
throw std::runtime_error(
"gr::tuntap_pdu::make: tun_alloc failed (are you running as root?)");
@@ -117,9 +127,10 @@ int tuntap_pdu_impl::tun_alloc(char* dev, int flags)
* the kernel will try to allocate the "next" device of the
* specified type
*/
- if (*dev)
+ if (*dev) {
+ // copy at most IFNAMSIZ - 1: If everything went well, the last byte is 0 anyway
strncpy(ifr.ifr_name, dev, IFNAMSIZ - 1);
-
+ }
/* try to create the device */
if ((err = ioctl(fd, TUNSETIFF, (void*)&ifr)) < 0) {
close(fd);