diff options
author | David Robillard <d@drobilla.net> | 2022-09-16 19:46:49 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-09-16 22:31:06 -0400 |
commit | 60feb44b88a662e3011b5c3c82c7cf3720540b68 (patch) | |
tree | 7a9ee8a8d5065dccdca53e09e3963995f8824e77 /include | |
parent | 1dc3dbdf5989a8f1ccb97e74ac30758e79b3a8f2 (diff) | |
download | chilbert-60feb44b88a662e3011b5c3c82c7cf3720540b68.tar.gz chilbert-60feb44b88a662e3011b5c3c82c7cf3720540b68.tar.bz2 chilbert-60feb44b88a662e3011b5c3c82c7cf3720540b68.zip |
Fix self-assignment
Diffstat (limited to 'include')
-rw-r--r-- | include/chilbert/DynamicBitVec.hpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/include/chilbert/DynamicBitVec.hpp b/include/chilbert/DynamicBitVec.hpp index 2bed27f..fe7a535 100644 --- a/include/chilbert/DynamicBitVec.hpp +++ b/include/chilbert/DynamicBitVec.hpp @@ -79,16 +79,18 @@ public: DynamicBitVec& operator=(const DynamicBitVec& vec) { - if (num_racks() < vec.num_racks()) { - m_racks = make_racks(vec.num_racks()); - m_size = vec.m_size; - memcpy(data(), vec.data(), data_size()); - } else if (vec.num_racks() > 0) { - m_size = vec.m_size; - memcpy(data(), vec.data(), data_size()); - } else { - m_size = 0; - m_racks.reset(); + if (&vec != this) { + if (num_racks() < vec.num_racks()) { + m_racks = make_racks(vec.num_racks()); + m_size = vec.m_size; + memcpy(data(), vec.data(), data_size()); + } else if (vec.num_racks() > 0) { + m_size = vec.m_size; + memcpy(data(), vec.data(), data_size()); + } else { + m_size = 0; + m_racks.reset(); + } } return *this; |