diff options
| author | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2023-08-18 22:16:59 +0200 |
|---|---|---|
| committer | Jeroen van Rijn <Kelimion@users.noreply.github.com> | 2023-08-18 22:16:59 +0200 |
| commit | 99d6a077fedf67632e0c44b44df7e1ac98228868 (patch) | |
| tree | 44f9bbc3df7c35de894ed3bc4b4bfa62a58a74b1 /core/bytes | |
| parent | b873651da73218ca723175d8cff2166141f34264 (diff) | |
_buffer_grow: Preserve allocator if already set via init_buffer_allocator
Fixes #2756
Diffstat (limited to 'core/bytes')
| -rw-r--r-- | core/bytes/buffer.odin | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/core/bytes/buffer.odin b/core/bytes/buffer.odin index 4375d8195..abfee6f2f 100644 --- a/core/bytes/buffer.odin +++ b/core/bytes/buffer.odin @@ -113,8 +113,11 @@ _buffer_grow :: proc(b: ^Buffer, n: int) -> int { if i, ok := _buffer_try_grow(b, n); ok { return i } + if b.buf == nil && n <= SMALL_BUFFER_SIZE { - b.buf = make([dynamic]byte, n, SMALL_BUFFER_SIZE) + // Fixes #2756 by preserving allocator if already set on Buffer via init_buffer_allocator + reserve(&b.buf, SMALL_BUFFER_SIZE) + resize(&b.buf, n) return 0 } |