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 | |
parent | 1dc3dbdf5989a8f1ccb97e74ac30758e79b3a8f2 (diff) | |
download | chilbert-60feb44b88a662e3011b5c3c82c7cf3720540b68.tar.gz chilbert-60feb44b88a662e3011b5c3c82c7cf3720540b68.tar.bz2 chilbert-60feb44b88a662e3011b5c3c82c7cf3720540b68.zip |
Fix self-assignment
-rw-r--r-- | .clang-tidy | 1 | ||||
-rw-r--r-- | include/chilbert/DynamicBitVec.hpp | 22 |
2 files changed, 12 insertions, 11 deletions
diff --git a/.clang-tidy b/.clang-tidy index b47495c..bdc03d3 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -8,7 +8,6 @@ Checks: > -*-non-private-member-variables-in-classes, -altera-*, -bugprone-easily-swappable-parameters, - -cert-oop54-cpp, -cppcoreguidelines-owning-memory, -cppcoreguidelines-pro-bounds-constant-array-index, -cppcoreguidelines-pro-bounds-pointer-arithmetic, 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; |