utils: Prevent capacity overflow in StructureOfArrays scaling logic

This commit is contained in:
Mathias Agopian
2026-03-30 17:31:16 -07:00
committed by Mathias Agopian
parent 0016c0808b
commit bdef97d52c

View File

@@ -295,7 +295,7 @@ public:
void ensureCapacity(size_t needed) {
if (UTILS_UNLIKELY(needed > mCapacity)) {
// not enough space, increase the capacity
const size_t capacity = (needed * 3 + 1) / 2;
const size_t capacity = (needed > SIZE_MAX / 3) ? needed : (needed * 3 + 1) / 2;
setCapacity(capacity);
}
}