]> sigrok.org Git - pulseview.git/commitdiff
StoreSession: Observe proper range order
authorSoeren Apel <redacted>
Thu, 5 Nov 2015 18:14:46 +0000 (19:14 +0100)
committerUwe Hermann <redacted>
Thu, 5 Nov 2015 20:36:19 +0000 (21:36 +0100)
When I wrote the original solution I wanted min() and abs()
to take care of this issue. However, I forgot that abs()
works on a difference of two uint64_t, so this subtraction
will underflow if the range is in the wrong order.
Converting them to int64_t isn't a good solution, so I'm now
using an ordinary condition instead.

pv/storesession.cpp

index 5500292a8df777563b624a5365a241bd7e93978b..bdb0f27981839087fac4f01c90ee05cac4b5cb47 100644 (file)
@@ -149,8 +149,13 @@ bool StoreSession::start()
                start_sample_ = 0;
                sample_count_ = segment->get_sample_count();
        } else {
                start_sample_ = 0;
                sample_count_ = segment->get_sample_count();
        } else {
-               start_sample_ = std::min(sample_range_.first, sample_range_.second);
-               sample_count_ = std::abs(sample_range_.second - sample_range_.first);
+               if (sample_range_.first > sample_range_.second) {
+                       start_sample_ = sample_range_.second;
+                       sample_count_ = sample_range_.first - sample_range_.second;
+               } else {
+                       start_sample_ = sample_range_.first;
+                       sample_count_ = sample_range_.second - sample_range_.first;
+               }
        }
 
        // Begin storing
        }
 
        // Begin storing