Created
October 12, 2025 10:48
-
-
Save froody/83a7d5678a5c82edf7de5b6f8faf40ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/src/openzl/common/vector.h b/src/openzl/common/vector.h | |
| index b082855..111808c 100644 | |
| --- a/src/openzl/common/vector.h | |
| +++ b/src/openzl/common/vector.h | |
| @@ -423,7 +423,10 @@ ZL_NODISCARD ZL_INLINE size_t GenericVector_resize( | |
| } | |
| if (GenericVector_reserve(vec, elementSize, size) < size) { | |
| - return vec->size; | |
| + vec->max_capacity = size; | |
| + if (GenericVector_reserve(vec, elementSize, size) < size) { | |
| + return vec->size; | |
| + } | |
| } | |
| // memset the new bytes to zero. | |
| @@ -453,8 +456,15 @@ ZL_NODISCARD ZL_INLINE bool GenericVector_pushBack( | |
| if (newCapacity == vec->capacity | |
| || GenericVector_reserve(vec, elementSize, newCapacity) | |
| < newCapacity) { | |
| - // Failed to increase capacity | |
| - return false; | |
| + if (newCapacity > vec->max_capacity) { | |
| + // We reached max capacity, cannot grow anymore | |
| + vec->max_capacity = newCapacity; | |
| + } | |
| + if (GenericVector_reserve(vec, elementSize, newCapacity) | |
| + < newCapacity) { | |
| + // Failed to increase capacity | |
| + return false; | |
| + } | |
| } | |
| } | |
| memcpy((void*)((uint8_t*)vec->data + elementSize * vec->size), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment