zig icon indicating copy to clipboard operation
zig copied to clipboard

Compiler panics over zero-terminated extern struct that contains nullable pointer field

Open DerryAlex opened this issue 2 years ago • 0 comments

Zig Version

0.11.0-dev.1711+dc1f50e50

Steps to Reproduce and Observed Behavior

const std = @import("std");

pub const File = extern struct {
    id: usize,
    data: ?*anyopaque,
};

pub fn main() void {
    var x: usize = 0;
    var files = [_:std.mem.zeroes(File)]File{ .{ .id = 1, .data = &x }, .{ .id = 2, .data = &x }, .{ .id = 3, .data = &x } };
    _ = files;
}
$ zig build-exe test.zig
panic: TODO implement readFromMemory for more types
Unable to dump stack trace: debug info stripped

If File is a struct or packed struct, compiler does not panic.

If data is *anyopaque, *u8 or [*:0]const u8, compiler does not panic.

If data is ?*anyopaque, ?*u8 or ?[*:0]const u8, compiler does panic.

Expected Behavior

No panic

DerryAlex avatar Mar 09 '23 06:03 DerryAlex