From: Soeren Apel Date: Tue, 3 May 2016 06:53:24 +0000 (+0200) Subject: Fix #792 by making sure we don't request samples that don't exist X-Git-Tag: pulseview-0.4.0~298 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=40ec0302a21055e85572ced539c457f0d8484c82;p=pulseview.git Fix #792 by making sure we don't request samples that don't exist --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 1a05907c..4f6bc41d 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -74,6 +74,7 @@ using std::cerr; using std::endl; using std::list; using std::map; +using std::max; using std::pair; using std::shared_ptr; using std::string; @@ -257,7 +258,8 @@ void MainWindow::export_file(shared_ptr format, const pv::util::Timestamp& start_time = view_->cursors()->first()->time(); const pv::util::Timestamp& end_time = view_->cursors()->second()->time(); - const uint64_t start_sample = start_time.convert_to() * samplerate; + const uint64_t start_sample = + std::max((double)0, start_time.convert_to() * samplerate); const uint64_t end_sample = end_time.convert_to() * samplerate; sample_range = std::make_pair(start_sample, end_sample); diff --git a/pv/storesession.cpp b/pv/storesession.cpp index 9a481dd8..2a4c8500 100644 --- a/pv/storesession.cpp +++ b/pv/storesession.cpp @@ -160,16 +160,20 @@ bool StoreSession::start() } // Check whether the user wants to export a certain sample range + uint64_t end_sample; + if (sample_range_.first == sample_range_.second) { start_sample_ = 0; sample_count_ = any_segment->get_sample_count(); } else { if (sample_range_.first > sample_range_.second) { start_sample_ = sample_range_.second; - sample_count_ = sample_range_.first - sample_range_.second; + end_sample = min(sample_range_.first, any_segment->get_sample_count()); + sample_count_ = end_sample - start_sample_; } else { start_sample_ = sample_range_.first; - sample_count_ = sample_range_.second - sample_range_.first; + end_sample = min(sample_range_.second, any_segment->get_sample_count()); + sample_count_ = end_sample - start_sample_; } }