Ryan Liptak 3fbb88c4bd Reader.defaultReadVec: Workaround bad r.end += r.vtable.stream() behavior
If `r.end` is updated in the `stream` implementation, then it's possible that `r.end += ...` will behave unexpectedly. What seems to happen is that it reverts back to its value before the function call and then the increment happens. Here's a reproduction:

```zig
test "fill when stream modifies `end` and returns 0" {
    var buf: [3]u8 = undefined;
    var zero_reader = infiniteZeroes(&buf);

    _ = try zero_reader.fill(1);
    try std.testing.expectEqual(buf.len, zero_reader.end);
}

pub fn infiniteZeroes(buf: []u8) std.Io.Reader {
    return .{
        .vtable = &.{
            .stream = stream,
        },
        .buffer = buf,
        .end = 0,
        .seek = 0,
    };
}

fn stream(r: *std.Io.Reader, _: *std.Io.Writer, _: std.Io.Limit) std.Io.Reader.StreamError!usize {
    @memset(r.buffer[r.seek..], 0);
    r.end = r.buffer.len;
    return 0;
}
```

When `fill` is called, it will call into `vtable.readVec` which in this case is `defaultReadVec`. In `defaultReadVec`:

- Before the `r.end += r.vtable.stream` line, `r.end` will be 0
- In `r.vtable.stream`, `r.end` is modified to 3 and it returns 0
- After the `r.end += r.vtable.stream` line, `r.end` will be 0 instead of the expected 3

Separating the `r.end += stream();` into two lines fixes the problem (and this separation is done elsewhere in `Reader` so it seems possible that this class of bug has been encountered before).

Potentially related issues:

- https://github.com/ziglang/zig/issues/4021
- https://github.com/ziglang/zig/issues/12064
2025-09-20 18:31:38 -07:00
..
2025-09-03 01:48:46 -07:00
2024-12-19 17:10:03 -05:00
2025-07-07 22:43:51 -07:00
2025-09-18 22:39:33 -07:00
2025-09-18 18:56:18 -04:00
2025-09-03 21:46:01 -07:00
2025-09-18 22:39:33 -07:00
2025-08-29 17:14:26 -07:00
2025-09-18 22:39:33 -07:00
2025-08-30 00:48:50 -07:00
2025-08-31 12:49:18 -07:00
2025-08-28 18:30:57 -07:00
2025-08-29 17:14:26 -07:00
2025-08-29 17:14:26 -07:00
2025-09-20 19:21:14 +02:00
2025-08-29 17:14:26 -07:00
2025-08-26 09:39:09 +02:00
2024-08-22 08:44:08 +02:00
2025-09-04 01:16:23 +02:00
2025-09-11 00:18:37 -07:00
2025-07-31 22:10:11 -07:00
2025-08-29 17:14:26 -07:00
2025-08-29 17:14:26 -07:00
2025-08-29 17:14:26 -07:00
2025-09-18 22:39:33 -07:00
2025-08-29 17:14:26 -07:00
2025-08-29 17:14:26 -07:00
2025-08-25 16:15:17 +02:00
2025-08-29 17:14:26 -07:00
2025-08-29 17:14:26 -07:00
2025-09-19 16:40:00 -07:00
2025-07-22 09:41:44 -07:00
2025-08-29 17:14:26 -07:00
2025-08-28 18:30:57 -07:00
2025-08-31 12:49:18 -07:00
2025-08-31 12:49:18 -07:00
2025-07-16 10:27:39 -07:00
2025-08-31 12:49:18 -07:00
2025-08-29 17:14:26 -07:00