PC-Lint warnings fixed:
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Thu, 22 Dec 2011 10:11:39 +0000 (08:11 -0200)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Thu, 22 Dec 2011 10:11:39 +0000 (08:11 -0200)
- Warning 1551: Function may throw exception '...' in destructor 'NetworkInterfaceList::~NetworkInterfaceList(void)';
- Info 774: Boolean within 'if' always evaluates to True.

src/host/networkinterfacelist.cpp

index f3015ab..4eb33b1 100644 (file)
 
 #include <boost/assert.hpp>
 
+#include <logfunc.hpp>
+
 using namespace std;
+using I2n::Logger::GlobalLogger;
 
 //-----------------------------------------------------------------------------
 // NetworkInterfaceList
@@ -78,18 +81,15 @@ const struct ifaddrs * NetworkInterfaceList::find_interface(
     const ifaddrs_t *ifa_current = IfaFirst;
     while ( ifa_current != NULL )
     {
-        if ( ifa_current->ifa_addr->sa_data != NULL )
-        {
-            const char *nic_name_current = ifa_current->ifa_name;
-            bool name_match = ( nic_name == nic_name_current );
+        const char *nic_name_current = ifa_current->ifa_name;
+        bool name_match = ( nic_name == nic_name_current );
 
-            const sa_family_t family_current = ifa_current->ifa_addr->sa_family;
-            bool family_match = ( family == family_current );
+        const sa_family_t family_current = ifa_current->ifa_addr->sa_family;
+        bool family_match = ( family == family_current );
 
-            if ( name_match && family_match )
-            {
-                return ifa_current;
-            }
+        if ( name_match && family_match )
+        {
+            return ifa_current;
         }
 
         ifa_current = ifa_current->ifa_next;
@@ -131,9 +131,16 @@ void NetworkInterfaceList::destroy_list()
 {
     BOOST_ASSERT( IfaFirst != NULL );
 
-    // The freeifaddrs() must release the linked list allocated by getifaddrs()
-    freeifaddrs( IfaFirst );
-    IfaFirst = NULL;
+    try {
+        // The freeifaddrs() must release the linked list allocated by getifaddrs()
+        freeifaddrs( IfaFirst );
+        IfaFirst = NULL;
+    }
+    catch ( ... )
+    {
+        GlobalLogger.error() << "Error: could not destroy network interface list."
+                << endl;
+    }
 }