From: Soeren Apel Date: Fri, 4 May 2018 21:53:31 +0000 (+0200) Subject: DecodeSignal: Prevent out-of-range exception X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=7dd518b81be3a446017040dc758003d236e158ff;p=pulseview.git DecodeSignal: Prevent out-of-range exception --- diff --git a/pv/data/decodesignal.cpp b/pv/data/decodesignal.cpp index d17c883c..d60c53e4 100644 --- a/pv/data/decodesignal.cpp +++ b/pv/data/decodesignal.cpp @@ -1020,8 +1020,9 @@ void DecodeSignal::start_srd_session() terminate_srd_session(); // Metadata is cleared also, so re-set it - srd_session_metadata_set(srd_session_, SRD_CONF_SAMPLERATE, - g_variant_new_uint64(segments_.at(current_segment_id_).samplerate)); + if (segments_.size() > 0) + srd_session_metadata_set(srd_session_, SRD_CONF_SAMPLERATE, + g_variant_new_uint64(segments_.at(current_segment_id_).samplerate)); for (const shared_ptr &dec : stack_) dec->apply_all_options(); srd_session_start(srd_session_); @@ -1052,8 +1053,9 @@ void DecodeSignal::start_srd_session() } // Start the session - srd_session_metadata_set(srd_session_, SRD_CONF_SAMPLERATE, - g_variant_new_uint64(segments_.at(current_segment_id_).samplerate)); + if (segments_.size() > 0) + srd_session_metadata_set(srd_session_, SRD_CONF_SAMPLERATE, + g_variant_new_uint64(segments_.at(current_segment_id_).samplerate)); srd_pd_output_callback_add(srd_session_, SRD_OUTPUT_ANN, DecodeSignal::annotation_callback, this); @@ -1075,8 +1077,9 @@ void DecodeSignal::terminate_srd_session() srd_session_terminate_reset(srd_session_); // Metadata is cleared also, so re-set it - srd_session_metadata_set(srd_session_, SRD_CONF_SAMPLERATE, - g_variant_new_uint64(segments_.at(current_segment_id_).samplerate)); + if (segments_.size() > 0) + srd_session_metadata_set(srd_session_, SRD_CONF_SAMPLERATE, + g_variant_new_uint64(segments_.at(current_segment_id_).samplerate)); for (const shared_ptr &dec : stack_) dec->apply_all_options(); }