Fix ignoring return value compiler warnings

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
This commit is contained in:
Curtis Gedak 2011-07-16 10:09:04 -06:00
parent 6c9d0cf6f1
commit f768cbd1b4
1 changed files with 16 additions and 12 deletions

View File

@ -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] ;
}
}
}