diff options
author | Dimitri Stolnikov <horiz0n@gmx.net> | 2013-09-28 13:46:36 +0200 |
---|---|---|
committer | Dimitri Stolnikov <horiz0n@gmx.net> | 2013-09-28 13:49:34 +0200 |
commit | a01a0b3cf583545a8dee443236c22e5ffea5230f (patch) | |
tree | 2c15f91452f05262e4b0be385e1b4d382c6ffb1f /lib/rtl/rtl_source_c.cc | |
parent | 40a5194276dcd109ff325cd32179caca5732a111 (diff) |
rtl: don't try to parse empty device index values
Diffstat (limited to 'lib/rtl/rtl_source_c.cc')
-rw-r--r-- | lib/rtl/rtl_source_c.cc | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/rtl/rtl_source_c.cc b/lib/rtl/rtl_source_c.cc index 6479b28..234faa3 100644 --- a/lib/rtl/rtl_source_c.cc +++ b/lib/rtl/rtl_source_c.cc @@ -101,14 +101,18 @@ rtl_source_c::rtl_source_c (const std::string &args) dict_t dict = params_to_dict(args); 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 */ } else { /* use the numeric value of the argument */ - try { - dev_index = boost::lexical_cast< unsigned int >( dict["rtl"] ); - } catch ( std::exception &ex ) { - throw std::runtime_error( - "Failed to use '" + dict["rtl"] + "' as index: " + ex.what()); + if ( value.length() ) { + try { + dev_index = boost::lexical_cast< unsigned int >( value ); + } catch ( std::exception &ex ) { + throw std::runtime_error( + "Failed to use '" + value + "' as index: " + ex.what()); + } } } } |