net: silence bogus stringop-truncation warning in strncpy

Change-Id: Id7467c201ee0499c4c19087c61511cdde1bc44aa
diff --git a/ndn-cxx/net/impl/netlink-message.hpp b/ndn-cxx/net/impl/netlink-message.hpp
index 4f0a74b..913c164 100644
--- a/ndn-cxx/net/impl/netlink-message.hpp
+++ b/ndn-cxx/net/impl/netlink-message.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2018 Regents of the University of California.
+ * Copyright (c) 2013-2020 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -275,10 +275,10 @@
   convertAttrValue(const uint8_t* val, size_t len, AttrValueTypeTag<std::string>)
   {
     auto str = reinterpret_cast<const char*>(val);
-    if (::strnlen(str, len) < len)
-      return std::string(str);
-    else
+    if (::strnlen(str, len) >= len)
       return nullopt;
+
+    return std::string(str);
   }
 
   static optional<ethernet::Address>
@@ -292,7 +292,8 @@
 
   template<typename IpAddress>
   static std::enable_if_t<std::is_same<IpAddress, boost::asio::ip::address_v4>::value ||
-                          std::is_same<IpAddress, boost::asio::ip::address_v6>::value, optional<IpAddress>>
+                          std::is_same<IpAddress, boost::asio::ip::address_v6>::value,
+                          optional<IpAddress>>
   convertAttrValue(const uint8_t* val, size_t len, AttrValueTypeTag<IpAddress>)
   {
     typename IpAddress::bytes_type bytes;
diff --git a/ndn-cxx/net/impl/netlink-socket.cpp b/ndn-cxx/net/impl/netlink-socket.cpp
index 0b00c50..52b37fa 100644
--- a/ndn-cxx/net/impl/netlink-socket.cpp
+++ b/ndn-cxx/net/impl/netlink-socket.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2019 Regents of the University of California.
+ * Copyright (c) 2013-2020 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -531,7 +531,7 @@
   auto attr = make_shared<FamilyNameAttribute>();
   attr->nla.nla_type = CTRL_ATTR_FAMILY_NAME;
   attr->nla.nla_len = NLA_HDRLEN + m_family.size() + 1;
-  ::strncpy(attr->name, m_family.data(), GENL_NAMSIZ);
+  std::strncpy(attr->name, m_family.data(), GENL_NAMSIZ - 1);
 
   m_sock.sendRequest(GENL_ID_CTRL, CTRL_CMD_GETFAMILY, attr.get(), attr->nla.nla_len,
                      // capture 'attr' to prevent its premature deallocation
diff --git a/ndn-cxx/net/impl/network-monitor-impl-netlink.cpp b/ndn-cxx/net/impl/network-monitor-impl-netlink.cpp
index 39e6505..4fcdabd 100644
--- a/ndn-cxx/net/impl/network-monitor-impl-netlink.cpp
+++ b/ndn-cxx/net/impl/network-monitor-impl-netlink.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2013-2019 Regents of the University of California.
+ * Copyright (c) 2013-2020 Regents of the University of California.
  *
  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
  *
@@ -305,7 +305,7 @@
     interface->setMtu(*mtu);
 
   auto state = attrs.getAttributeByType<uint8_t>(IFLA_OPERSTATE);
-  updateInterfaceState(*interface, state ? *state : linux_if::OPER_STATE_UNKNOWN);
+  updateInterfaceState(*interface, state.value_or(linux_if::OPER_STATE_UNKNOWN));
 
   if (it == m_interfaces.end()) {
     NDN_LOG_DEBUG("  adding interface " << interface->getName());