From: Joel Holdsworth Date: Sat, 29 Sep 2012 09:09:50 +0000 (+0100) Subject: Fixes for data sizes greater than zero X-Git-Tag: pulseview-0.1.0~294 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=77bff0b13e820abf22422c8ede0dfe498b48951b;p=pulseview.git Fixes for data sizes greater than zero --- diff --git a/datasnapshot.cpp b/datasnapshot.cpp index 80d9ba43..df411f3d 100644 --- a/datasnapshot.cpp +++ b/datasnapshot.cpp @@ -26,7 +26,7 @@ DataSnapshot::DataSnapshot(int unit_size) : _data(NULL), - _data_length(0), + _sample_count(0), _unit_size(unit_size) { assert(_unit_size > 0); @@ -39,12 +39,13 @@ DataSnapshot::~DataSnapshot() uint64_t DataSnapshot::get_sample_count() { - return _data_length / _unit_size; + return _sample_count; } -void DataSnapshot::append_data(void *data, uint64_t length) +void DataSnapshot::append_data(void *data, uint64_t samples) { - _data = realloc(_data, _data_length + length); - memcpy((uint8_t*)_data + _data_length, data, length); - _data_length += length; + _data = realloc(_data, (_sample_count + samples) * _unit_size); + memcpy((uint8_t*)_data + _sample_count * _unit_size, + data, samples * _unit_size); + _sample_count += samples; } diff --git a/datasnapshot.h b/datasnapshot.h index f3bb3e21..c768e112 100644 --- a/datasnapshot.h +++ b/datasnapshot.h @@ -32,10 +32,10 @@ public: uint64_t get_sample_count(); protected: - void append_data(void *data, uint64_t length); + void append_data(void *data, uint64_t samples); protected: void *_data; - uint64_t _data_length; + uint64_t _sample_count; int _unit_size; }; diff --git a/logicdatasnapshot.cpp b/logicdatasnapshot.cpp index d01916a7..10744cf7 100644 --- a/logicdatasnapshot.cpp +++ b/logicdatasnapshot.cpp @@ -55,7 +55,6 @@ void LogicDataSnapshot::append_payload( { assert(_unit_size == logic.unitsize); - const uint64_t prev_length = _data_length; append_data(logic.data, logic.length); // Generate the first mip-map from the data @@ -84,7 +83,7 @@ void LogicDataSnapshot::append_payload_to_mipmap() // Expand the data buffer to fit the new samples prev_length = m0.length; - m0.length = _data_length / MipMapScaleFactor; + m0.length = _sample_count / MipMapScaleFactor; // Break off if there are no new samples to compute if(m0.length == prev_length) @@ -160,7 +159,7 @@ void LogicDataSnapshot::append_payload_to_mipmap() uint64_t LogicDataSnapshot::get_sample(uint64_t index) const { assert(_data); - assert(index >= 0 && index < _data_length); + assert(index >= 0 && index < _sample_count); return *(uint64_t*)((uint8_t*)_data + index * _unit_size); }