authorgravatar for elliot.huang.signed@gmail.combinarycraft007 <elliot.huang.signed@gmail.com> 2025-09-01 17:01:54+08:00
committergravatar for elliot.huang.signed@gmail.combinarycraft007 <elliot.huang.signed@gmail.com> 2025-09-01 17:01:54+08:00
log00b0beb682881da083b548423019483924736c1e
treed0ba12d0dc7e049ab734b6039bae32b3f00f5c81
parentbc7955306e3480fc065277d0b6c5abb6797a27ae

lzma2: fix array list looping logic in appendLz


1 files changed, 7 insertions(+), 1 deletions(-)

lib/std/compress/lzma2.zig+7-1
...@@ -83,11 +83,17 @@ pub const AccumBuffer = struct {...@@ -83,11 +83,17 @@ pub const AccumBuffer = struct {
83 return error.CorruptInput;83 return error.CorruptInput;
84 }84 }
8585
86 // ensure we have enough capacity for all new bytes.
87 // This prevents the buffer's memory from being reallocated (and freed)
88 // while we are still reading from it.
89 try self.buf.ensureTotalCapacity(allocator, buf_len + len);
90
86 var offset = buf_len - dist;91 var offset = buf_len - dist;
87 var i: usize = 0;92 var i: usize = 0;
88 while (i < len) : (i += 1) {93 while (i < len) : (i += 1) {
89 const x = self.buf.items[offset];94 const x = self.buf.items[offset];
90 try self.buf.append(allocator, x);95 // Since capacity is guaranteed, it's safe to use appendAssumeCapacity.
96 self.buf.appendAssumeCapacity(x);
91 offset += 1;97 offset += 1;
92 }98 }
93 self.len += len;99 self.len += len;