diff options
| author | Laytan Laats <laytanlaats@hotmail.com> | 2023-05-09 21:25:15 +0200 |
|---|---|---|
| committer | Laytan Laats <laytanlaats@hotmail.com> | 2023-05-09 21:25:15 +0200 |
| commit | 7a04b7262e489248666b112d4ecf449dd8a7e736 (patch) | |
| tree | 53bcc2a5a5c5380a6161a11401c608a3f2b59cd5 /core/bytes | |
| parent | 29e476201154821a06d11d29bb662f4c51f9fcca (diff) | |
fix bytes.buffer_init_allocator not using given allocator if len/cap is 0
Diffstat (limited to 'core/bytes')
| -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) |