]> sigrok.org Git - pulseview.git/blobdiff - pv/data/segment.cpp
Fix clang warning: shifting a negative signed value is undefined
[pulseview.git] / pv / data / segment.cpp
index 111b62b71aadf0c43189540050c55e92de29dc43..754e300deacdab58af440dc290e4bbb7ba001dfc 100644 (file)
@@ -52,7 +52,7 @@ uint64_t Segment::get_sample_count() const
        return sample_count_;
 }
 
-double Segment::start_time() const
+const pv::util::Timestamp& Segment::start_time() const
 {
        return start_time_;
 }
@@ -78,8 +78,9 @@ void Segment::set_capacity(const uint64_t new_capacity)
 
        assert(capacity_ >= sample_count_);
        if (new_capacity > capacity_) {
-               capacity_ = new_capacity;
+               // If we're out of memory, this will throw std::bad_alloc
                data_.resize((new_capacity * unit_size_) + sizeof(uint64_t));
+               capacity_ = new_capacity;
        }
 }
 
@@ -97,9 +98,8 @@ void Segment::append_data(void *data, uint64_t samples)
 
        // Ensure there's enough capacity to copy.
        const uint64_t free_space = capacity_ - sample_count_;
-       if (free_space < samples) {
+       if (free_space < samples)
                set_capacity(sample_count_ + samples);
-       }
 
        memcpy((uint8_t*)data_.data() + sample_count_ * unit_size_,
                data, samples * unit_size_);