]> sigrok.org Git - pulseview.git/commitdiff
Fix #1038 by catching invalid cursor ranges
authorSoeren Apel <redacted>
Sat, 10 Feb 2018 09:52:16 +0000 (10:52 +0100)
committerSoeren Apel <redacted>
Sat, 10 Feb 2018 22:18:33 +0000 (23:18 +0100)
pv/storesession.cpp
pv/toolbars/mainbar.cpp

index 50815c26dcedfcaff7716f115b2eb376c371960a..494f2db3b91e7b8fe34ea1cfa56471f5ba4a8fc5 100644 (file)
@@ -145,6 +145,7 @@ bool StoreSession::start()
        uint64_t end_sample;
 
        if (sample_range_.first == sample_range_.second) {
        uint64_t end_sample;
 
        if (sample_range_.first == sample_range_.second) {
+               // No sample range specified, save everything we have
                start_sample_ = 0;
                sample_count_ = any_segment->get_sample_count();
        } else {
                start_sample_ = 0;
                sample_count_ = any_segment->get_sample_count();
        } else {
@@ -159,6 +160,12 @@ bool StoreSession::start()
                }
        }
 
                }
        }
 
+       // Make sure the sample range is valid
+       if (start_sample_ > any_segment->get_sample_count()) {
+               error_ = tr("Can't save range without sample data.");
+               return false;
+       }
+
        // Begin storing
        try {
                const auto context = session_.device_manager().context();
        // Begin storing
        try {
                const auto context = session_.device_manager().context();
index 1879693d57a31c01bc87458f556d67dd01db7506..34b120fec11ce0ec14bf21f16cc717e7b9d74222 100644 (file)
@@ -612,6 +612,13 @@ void MainBar::export_file(shared_ptr<OutputFormat> format, bool selection_only)
                const uint64_t end_sample = (uint64_t)max(
                        (double)0, end_time.convert_to<double>() * samplerate);
 
                const uint64_t end_sample = (uint64_t)max(
                        (double)0, end_time.convert_to<double>() * samplerate);
 
+               if ((start_sample == 0) && (end_sample == 0)) {
+                       // Both cursors are negative and were clamped to 0
+                       show_session_error(tr("Invalid Range"), tr("The cursors don't " \
+                                       "define a valid range of samples."));
+                       return;
+               }
+
                sample_range = make_pair(start_sample, end_sample);
        } else {
                sample_range = make_pair(0, 0);
                sample_range = make_pair(start_sample, end_sample);
        } else {
                sample_range = make_pair(0, 0);