-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior
Milestone
Description
Zig Version
0.10.0
Steps to Reproduce and Observed Behavior
I've encountered this issue while working on a protobuf implementation. The following is the smallest repro i can make. Setting oom_trigger = false allows the program to compile and the test segfaults as expected. The problem seems to be related to using the io.limitedReader() (possibly related to error the error set analysis?). Its strange to me that this only happens after introducing the io.limitedReader().
// /tmp/test.zig
const std = @import("std");
const Allocator = std.mem.Allocator;
pub const Error = error{ Overflow, EndOfStream };
const oom_trigger = true;
const A = struct {
b: *B = undefined,
fn deserialize(self: *A, allocator: Allocator, reader: anytype) Error!void {
try self.b.deserialize(allocator, reader);
}
};
const B = struct {
a: *A = undefined,
fn deserialize(self: *B, allocator: Allocator, reader: anytype) Error!void {
if (oom_trigger) {
var limreader = std.io.limitedReader(reader, 1);
try self.a.deserialize(allocator, limreader.reader());
} else {
try self.a.deserialize(allocator, reader);
}
}
};
test {
var x: A = .{};
var fbs = std.io.fixedBufferStream("\xFF\xFF\xFF\x00");
try x.deserialize(undefined, fbs.reader());
}$ zig version
0.10.0
$ zig test /tmp/test.zig
Semantic Analysis [10882] readByte... ^C
# Note: I've killed the program here with ctrl+cpossibly related to #4572
Expected Behavior
the test should compile and segfault due to infinite recursion (a.deserialize() -> b.deserialize() -> a.deserialize() ...).
lin72h
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior