| ... | ... | @@ -246,34 +246,18 @@ pub fn appendRemaining( |
| 246 | 246 | limit: Limit, |
| 247 | 247 | ) LimitedAllocError!void { |
| 248 | 248 | assert(r.buffer.len != 0); // Needed to detect limit exceeded without losing data. |
| 249 | | const buffer = r.buffer; |
| 250 | | const buffer_contents = buffer[r.seek..r.end]; |
| 251 | | const copy_len = limit.minInt(buffer_contents.len); |
| 252 | | try list.ensureUnusedCapacity(gpa, copy_len); |
| 253 | | @memcpy(list.unusedCapacitySlice()[0..copy_len], buffer[0..copy_len]); |
| 254 | | list.items.len += copy_len; |
| 255 | | r.seek += copy_len; |
| 256 | | if (copy_len == buffer_contents.len) { |
| 257 | | r.seek = 0; |
| 258 | | r.end = 0; |
| 259 | | } |
| 260 | | var remaining = limit.subtract(copy_len).?; |
| 261 | | while (true) { |
| 262 | | try list.ensureUnusedCapacity(gpa, 1); |
| 249 | var remaining = limit; |
| 250 | while (remaining.nonzero()) { |
| 251 | try list.ensureUnusedCapacity(gpa, r.bufferedLen() + 1); |
| 263 | 252 | const dest = remaining.slice(list.unusedCapacitySlice()); |
| 264 | | const additional_buffer: []u8 = if (@intFromEnum(remaining) == dest.len) buffer else &.{}; |
| 265 | | const n = readVec(r, &.{ dest, additional_buffer }) catch |err| switch (err) { |
| 253 | const n = readVecLimit(r, &.{dest}, .unlimited) catch |err| switch (err) { |
| 266 | 254 | error.EndOfStream => break, |
| 267 | 255 | error.ReadFailed => return error.ReadFailed, |
| 268 | 256 | }; |
| 269 | | if (n > dest.len) { |
| 270 | | r.end = n - dest.len; |
| 271 | | list.items.len += dest.len; |
| 272 | | return error.StreamTooLong; |
| 273 | | } |
| 274 | 257 | list.items.len += n; |
| 275 | 258 | remaining = remaining.subtract(n).?; |
| 276 | 259 | } |
| 260 | if (r.bufferedLen() != 0) return error.StreamTooLong; |
| 277 | 261 | } |
| 278 | 262 | |
| 279 | 263 | /// Writes bytes from the internally tracked stream position to `data`. |