From 6947812ad2d9d6060ee64725fdcfa40603fba3a7 Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Thu, 22 Dec 2011 08:11:39 -0200 Subject: [PATCH] PC-Lint warnings fixed: - Warning 1551: Function may throw exception '...' in destructor 'NetworkInterfaceList::~NetworkInterfaceList(void)'; - Info 774: Boolean within 'if' always evaluates to True. --- src/host/networkinterfacelist.cpp | 33 ++++++++++++++++++++------------- 1 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/host/networkinterfacelist.cpp b/src/host/networkinterfacelist.cpp index f3015ab..4eb33b1 100644 --- a/src/host/networkinterfacelist.cpp +++ b/src/host/networkinterfacelist.cpp @@ -24,7 +24,10 @@ #include +#include + 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; + } } -- 1.7.1