diff options
-rw-r--r-- | gr-uhd/lib/gr_uhd_common.h | 15 | ||||
-rw-r--r-- | gr-uhd/lib/gr_uhd_usrp_sink.cc | 4 | ||||
-rw-r--r-- | gr-uhd/lib/gr_uhd_usrp_source.cc | 4 |
3 files changed, 19 insertions, 4 deletions
diff --git a/gr-uhd/lib/gr_uhd_common.h b/gr-uhd/lib/gr_uhd_common.h index f2433b288..2582cd68d 100644 --- a/gr-uhd/lib/gr_uhd_common.h +++ b/gr-uhd/lib/gr_uhd_common.h @@ -39,4 +39,19 @@ static inline void gr_uhd_check_abi(void){ #endif } +/*! + * The stream args ensure function sanitizes random user input. + * We may extend this to handle more things in the future, + * but ATM it ensures that the channels are initialized. + */ +static inline uhd::stream_args_t stream_args_ensure(const uhd::stream_args_t &args) +{ + uhd::stream_args_t sanitized = args; + if (sanitized.channels.empty()) + { + sanitized.channels.push_back(0); + } + return sanitized; +} + #endif /* INCLUDED_GR_UHD_COMMON_H */ diff --git a/gr-uhd/lib/gr_uhd_usrp_sink.cc b/gr-uhd/lib/gr_uhd_usrp_sink.cc index ad3f4ffdf..b89f68b48 100644 --- a/gr-uhd/lib/gr_uhd_usrp_sink.cc +++ b/gr-uhd/lib/gr_uhd_usrp_sink.cc @@ -57,7 +57,7 @@ public: gr_make_io_signature(0, 0, 0) ), _stream_args(stream_args), - _nchan(std::max<size_t>(1, stream_args.channels.size())), + _nchan(stream_args.channels.size()), _stream_now(_nchan == 1), _start_time_set(false) { @@ -530,6 +530,6 @@ boost::shared_ptr<uhd_usrp_sink> uhd_make_usrp_sink( ){ gr_uhd_check_abi(); return boost::shared_ptr<uhd_usrp_sink>( - new uhd_usrp_sink_impl(device_addr, stream_args) + new uhd_usrp_sink_impl(device_addr, stream_args_ensure(stream_args)) ); } diff --git a/gr-uhd/lib/gr_uhd_usrp_source.cc b/gr-uhd/lib/gr_uhd_usrp_source.cc index 1d5a65f76..126023d1a 100644 --- a/gr-uhd/lib/gr_uhd_usrp_source.cc +++ b/gr-uhd/lib/gr_uhd_usrp_source.cc @@ -60,7 +60,7 @@ public: args_to_io_sig(stream_args) ), _stream_args(stream_args), - _nchan(std::max<size_t>(1, stream_args.channels.size())), + _nchan(stream_args.channels.size()), _stream_now(_nchan == 1), _tag_now(false), _start_time_set(false) @@ -593,6 +593,6 @@ boost::shared_ptr<uhd_usrp_source> uhd_make_usrp_source( ){ gr_uhd_check_abi(); return boost::shared_ptr<uhd_usrp_source>( - new uhd_usrp_source_impl(device_addr, stream_args) + new uhd_usrp_source_impl(device_addr, stream_args_ensure(stream_args)) ); } |