Explorar o código

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
gingerBill %!s(int64=2) %!d(string=hai) anos
pai
achega
911c98e235
Modificáronse 1 ficheiros con 5 adicións e 0 borrados
  1. 5 0
      core/bytes/buffer.odin

+ 5 - 0
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)