| ... | @@ -79,17 +79,18 @@ pub const AccumBuffer = struct { | ... | @@ -79,17 +79,18 @@ pub const AccumBuffer = struct { |
| 79 | _ = writer; | 79 | _ = writer; |
| 80 | | 80 | |
| 81 | const buf_len = self.buf.items.len; | 81 | const buf_len = self.buf.items.len; |
| 82 | if (dist > buf_len) { | 82 | if (dist > buf_len) return error.CorruptInput; |
| 83 | return error.CorruptInput; | | |
| 84 | } | | |
| 85 | | 83 | |
| 86 | var offset = buf_len - dist; | 84 | try self.buf.ensureUnusedCapacity(allocator, len); |
| 87 | var i: usize = 0; | 85 | const buffer = self.buf.allocatedSlice(); |
| 88 | while (i < len) : (i += 1) { | 86 | const src = buffer[buf_len - dist ..][0..len]; |
| 89 | const x = self.buf.items[offset]; | 87 | const dst = buffer[buf_len..][0..len]; |
| 90 | try self.buf.append(allocator, x); | 88 | |
| 91 | offset += 1; | 89 | // This is not a @memmove; it intentionally repeats patterns caused by |
| 92 | } | 90 | // iterating one byte at a time. |
| | 91 | for (dst, src) |*d, s| d.* = s; |
| | 92 | |
| | 93 | self.buf.items.len = buf_len + len; |
| 93 | self.len += len; | 94 | self.len += len; |
| 94 | } | 95 | } |
| 95 | | 96 | |