From: Soeren Apel Date: Thu, 5 Nov 2015 18:14:46 +0000 (+0100) Subject: StoreSession: Observe proper range order X-Git-Tag: pulseview-0.3.0~48 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=3e8a7cc6af5558a249c114b1609ececa2a381774 StoreSession: Observe proper range order 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. --- diff --git a/pv/storesession.cpp b/pv/storesession.cpp index 5500292a..bdb0f279 100644 --- a/pv/storesession.cpp +++ b/pv/storesession.cpp @@ -149,8 +149,13 @@ bool StoreSession::start() 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