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.
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