using std::endl;
using std::list;
using std::map;
+using std::max;
using std::pair;
using std::shared_ptr;
using std::string;
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<double>() * samplerate;
+ const uint64_t start_sample =
+ std::max((double)0, start_time.convert_to<double>() * samplerate);
const uint64_t end_sample = end_time.convert_to<double>() * samplerate;
sample_range = std::make_pair(start_sample, end_sample);
}
// 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_;
}
}