Skip to content

Commit

Permalink
Fixed wrong buffer substitution in Signal class
Browse files Browse the repository at this point in the history
With the CONTIGUOUS_ZEROCOPY signal data format, since the memory is not owned by the Signal object it should not be modified. Changing the buffer in this case means only updating the pointer to the first element and the signal width.
  • Loading branch information
diegoferigo committed Apr 6, 2018
1 parent 6136239 commit 6da879a
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions toolbox/src/base/Signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,8 @@ bool Signal::setBuffer(const T* data, const unsigned& length)
std::copy(data, data + length, getBuffer<T>());
break;
case DataFormat::CONTIGUOUS_ZEROCOPY:
// Reset current data
std::fill(getBuffer<T>(), getBuffer<T>() + m_width, 0);
// Copy new data
std::copy(data, data + length, getBuffer<T>());
// Override the buffer pointer
m_bufferPtr = static_cast<void*>(const_cast<T*>(data));
// Update the width
m_width = length;
break;
Expand Down

0 comments on commit 6da879a

Please sign in to comment.