]> sigrok.org Git - pulseview.git/commitdiff
Segment: Implement temporary workaround for #1284
authorSoeren Apel <redacted>
Sat, 13 Oct 2018 12:04:33 +0000 (14:04 +0200)
committerSoeren Apel <redacted>
Sat, 13 Oct 2018 13:37:04 +0000 (15:37 +0200)
pv/data/segment.cpp

index a71d49ca6d27b9f2098a844b4c425c9fdfe765f3..6ea17ff6d0ba2861af7d3963538771e51d2159e6 100644 (file)
@@ -54,7 +54,7 @@ Segment::Segment(uint32_t segment_id, uint64_t samplerate, unsigned int unit_siz
        chunk_size_ = min(MaxChunkSize, (MaxChunkSize / unit_size_) * unit_size_);
 
        // Create the initial chunk
-       current_chunk_ = new uint8_t[chunk_size_];
+       current_chunk_ = new uint8_t[chunk_size_ + 7];  /* FIXME +7 is workaround for #1284 */
        data_chunks_.push_back(current_chunk_);
        used_samples_ = 0;
        unused_samples_ = chunk_size_ / unit_size_;
@@ -121,7 +121,7 @@ void Segment::free_unused_memory()
 
        if (current_chunk_) {
                // No more data will come in, so re-create the last chunk accordingly
-               uint8_t* resized_chunk = new uint8_t[used_samples_ * unit_size_];
+               uint8_t* resized_chunk = new uint8_t[used_samples_ * unit_size_ + 7];  /* FIXME +7 is workaround for #1284 */
                memcpy(resized_chunk, current_chunk_, used_samples_ * unit_size_);
 
                delete[] current_chunk_;
@@ -144,7 +144,7 @@ void Segment::append_single_sample(void *data)
        unused_samples_--;
 
        if (unused_samples_ == 0) {
-               current_chunk_ = new uint8_t[chunk_size_];
+               current_chunk_ = new uint8_t[chunk_size_ + 7];  /* FIXME +7 is workaround for #1284 */
                data_chunks_.push_back(current_chunk_);
                used_samples_ = 0;
                unused_samples_ = chunk_size_ / unit_size_;
@@ -190,7 +190,7 @@ void Segment::append_samples(void* data, uint64_t samples)
                                // This way, memory allocation will fail early enough to let
                                // PV remain alive. Otherwise, PV will crash in a random
                                // memory-allocating part of the application.
-                               current_chunk_ = new uint8_t[chunk_size_];
+                               current_chunk_ = new uint8_t[chunk_size_ + 7];  /* FIXME +7 is workaround for #1284 */
 
                                const int dummy_size = 2 * chunk_size_;
                                auto dummy_chunk = new uint8_t[dummy_size];