Skip to content

Commit d83b95c

Browse files
brianvarandrewrk
authored andcommitted
fixed .fixed flush recursion
1 parent f551c7c commit d83b95c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/std/Io/Writer.zig

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,10 @@ pub const FileError = error{
114114
/// Writes to `buffer` and returns `error.WriteFailed` when it is full.
115115
pub fn fixed(buffer: []u8) Writer {
116116
return .{
117-
.vtable = &.{ .drain = fixedDrain },
117+
.vtable = &.{
118+
.drain = fixedDrain,
119+
.flush = noopFlush,
120+
},
118121
.buffer = buffer,
119122
};
120123
}
@@ -244,6 +247,15 @@ pub fn noopFlush(w: *Writer) Error!void {
244247
_ = w;
245248
}
246249

250+
test "fixed buffer flush" {
251+
var buffer: [1]u8 = undefined;
252+
var writer: std.io.Writer = .fixed(&buffer);
253+
254+
try writer.writeByte(10);
255+
try writer.flush();
256+
try testing.expectEqual(10, buffer[0]);
257+
}
258+
247259
/// Calls `VTable.drain` but hides the last `preserve_length` bytes from the
248260
/// implementation, keeping them buffered.
249261
pub fn drainPreserve(w: *Writer, preserve_length: usize) Error!void {

0 commit comments

Comments
 (0)