rtl: don't try to parse empty device index values

This commit is contained in:
Dimitri Stolnikov 2013-09-28 13:46:36 +02:00
parent 40a5194276
commit a01a0b3cf5
1 changed files with 10 additions and 6 deletions

View File

@ -101,14 +101,18 @@ rtl_source_c::rtl_source_c (const std::string &args)
dict_t dict = params_to_dict(args); dict_t dict = params_to_dict(args);
if (dict.count("rtl")) { if (dict.count("rtl")) {
if ( (index = rtlsdr_get_index_by_serial( dict["rtl"].c_str() )) >= 0 ) { std::string value = dict["rtl"];
if ( (index = rtlsdr_get_index_by_serial( value.c_str() )) >= 0 ) {
dev_index = index; /* use the resolved index value */ dev_index = index; /* use the resolved index value */
} else { /* use the numeric value of the argument */ } else { /* use the numeric value of the argument */
try { if ( value.length() ) {
dev_index = boost::lexical_cast< unsigned int >( dict["rtl"] ); try {
} catch ( std::exception &ex ) { dev_index = boost::lexical_cast< unsigned int >( value );
throw std::runtime_error( } catch ( std::exception &ex ) {
"Failed to use '" + dict["rtl"] + "' as index: " + ex.what()); throw std::runtime_error(
"Failed to use '" + value + "' as index: " + ex.what());
}
} }
} }
} }