From f768cbd1b4e186acab1ba9c434de0cac8392a69b Mon Sep 17 00:00:00 2001 From: Curtis Gedak Date: Sat, 16 Jul 2011 10:09:04 -0600 Subject: [PATCH] Fix ignoring return value compiler warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add code to handle situation where realpath might return a NULL value. Prior to this change the compiler would complain with the following message: error: ignoring return value of ‘char* realpath(const char*, char*)’, declared with attribute warn_unused_result --- src/DMRaid.cc | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/DMRaid.cc b/src/DMRaid.cc index da825305..9b51af8a 100644 --- a/src/DMRaid.cc +++ b/src/DMRaid.cc @@ -128,12 +128,14 @@ bool DMRaid::is_dmraid_device( const Glib::ustring & dev_path ) //Path is a symbolic link so find real path char c_str[4096+1] ; //FIXME: it seems realpath is very unsafe to use (manpage)... - realpath( dev_path .c_str(), c_str ) ; - Glib::ustring tmp_path = c_str ; - if ( tmp_path .length() > 0 ) - for ( unsigned int k=0; k < dmraid_devices .size(); k++ ) - if ( tmp_path .find( dmraid_devices[k] ) != Glib::ustring::npos ) - device_found = true ; + if ( realpath( dev_path .c_str(), c_str ) != NULL ) + { + Glib::ustring tmp_path = c_str ; + if ( tmp_path .length() > 0 ) + for ( unsigned int k=0; k < dmraid_devices .size(); k++ ) + if ( tmp_path .find( dmraid_devices[k] ) != Glib::ustring::npos ) + device_found = true ; + } } } @@ -196,12 +198,14 @@ Glib::ustring DMRaid::get_dmraid_name( const Glib::ustring & dev_path ) //Path is a symbolic link so find real path char c_str[4096+1] ; //FIXME: it seems realpath is very unsafe to use (manpage)... - realpath( dev_path .c_str(), c_str ) ; - Glib::ustring tmp_path = c_str ; - if ( tmp_path .length() > 0 ) - for ( unsigned int k=0; k < dmraid_devices .size(); k++ ) - if ( tmp_path .find( dmraid_devices[k] ) != Glib::ustring::npos ) - dmraid_name = dmraid_devices[k] ; + if( realpath( dev_path .c_str(), c_str ) != NULL ) + { + Glib::ustring tmp_path = c_str ; + if ( tmp_path .length() > 0 ) + for ( unsigned int k=0; k < dmraid_devices .size(); k++ ) + if ( tmp_path .find( dmraid_devices[k] ) != Glib::ustring::npos ) + dmraid_name = dmraid_devices[k] ; + } } }