diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2023-05-18 11:24:27 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-18 11:24:27 +0100 |
| commit | 911c98e2351c1b0d27b63ef51184b72e5903c4fd (patch) | |
| tree | 59749feecf72cb65bfaa0c1d1e5e01831c2d9e8c /core/bytes/buffer.odin | |
| parent | 535c64c31837bdb8aa76f2f332fcd87819d393a2 (diff) | |
| parent | 7a04b7262e489248666b112d4ecf449dd8a7e736 (diff) | |
Merge pull request #2525 from laytan/fix-buffer-init-cap-0-wrong-allocator
fix bytes.buffer_init_allocator not using given allocator if len/cap is 0
Diffstat (limited to 'core/bytes/buffer.odin')
| -rw-r--r-- | core/bytes/buffer.odin | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/core/bytes/buffer.odin b/core/bytes/buffer.odin index bba834f7e..b60a8e877 100644 --- a/core/bytes/buffer.odin +++ b/core/bytes/buffer.odin @@ -38,6 +38,11 @@ buffer_init_string :: proc(b: ^Buffer, s: string) { } buffer_init_allocator :: proc(b: ^Buffer, len, cap: int, allocator := context.allocator) { + if b.buf == nil { + b.buf = make([dynamic]byte, len, cap, allocator) + return + } + b.buf.allocator = allocator reserve(&b.buf, cap) resize(&b.buf, len) |