diff options
| author | Darren Wihandi <65404740+fairywreath@users.noreply.github.com> | 2025-01-28 20:21:57 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-28 17:21:57 -0800 |
| commit | 1f99c2086cab3a259c786373ba8d5608e0e1f430 (patch) | |
| tree | d0a2404c83265afa98115a177773072bd51425d2 /source/core | |
| parent | f4e3692dbea505a93424c8414778620d52817fdd (diff) | |
Fix UIntSet calcSubtract to handle mismatched buffer sizes (#6205)
* fix calcSubtract on UIntSet
* add test
---------
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/core')
| -rw-r--r-- | source/core/slang-uint-set.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/source/core/slang-uint-set.cpp b/source/core/slang-uint-set.cpp index ec086c5de..1098db6d5 100644 --- a/source/core/slang-uint-set.cpp +++ b/source/core/slang-uint-set.cpp @@ -156,11 +156,23 @@ void UIntSet::subtractWith(const UIntSet& set) /* static */ void UIntSet::calcSubtract(UIntSet& outRs, const UIntSet& set1, const UIntSet& set2) { - outRs.resizeBackingBufferDirectly(set1.m_buffer.getCount()); + const auto set1Count = set1.m_buffer.getCount(); + const auto set2Count = set2.m_buffer.getCount(); - const Index minCount = Math::Min(set1.m_buffer.getCount(), set2.m_buffer.getCount()); - for (Index i = 0; i < minCount; i++) - outRs.m_buffer[i] = set1.m_buffer[i] & (~set2.m_buffer[i]); + outRs.resizeBackingBufferDirectly(set1Count); + + for (Index i = 0; i < set1Count; i++) + { + if (i < set2Count) + { + outRs.m_buffer[i] = set1.m_buffer[i] & (~set2.m_buffer[i]); + } + else + { + // If `set2` is smaller, copy the remaining values from `set1` + outRs.m_buffer[i] = set1.m_buffer[i]; + } + } } /* static */ bool UIntSet::hasIntersection(const UIntSet& set1, const UIntSet& set2) |
