Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Std.debug.print crashes with max_depth overflow on vectors #22376

Open
christopherliu830 opened this issue Jan 1, 2025 · 0 comments · May be fixed by #22381
Open

Std.debug.print crashes with max_depth overflow on vectors #22376

christopherliu830 opened this issue Jan 1, 2025 · 0 comments · May be fixed by #22381
Labels
bug Observed behavior contradicts documented or intended behavior standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@christopherliu830
Copy link

Zig Version

0.14.0-dev.2384+cbc05e0b1

Steps to Reproduce and Observed Behavior

On an empty project (zig init), with this main.zig code:

const std = @import("std");

const Mat = struct {
    values: [4]@Vector(4, f32),
};

const Struct = struct {
    mat: Mat,
};

pub fn main() !void {
    const m = Struct {
        .mat = .{
            .values = .{
                .{0, 0, 0, 0},
                .{0, 0, 0, 0},
                .{0, 0, 0, 0},
                .{0, 0, 0, 0},
            }
        }
    };

    std.debug.print("struct {}\n", .{m});
}

Output

struct main.Struct{ .mat = main.Mat{ .values = { { thread 7708 panic: integer overflow
C:\...\zig\0.14.0-dev.2384+cbc05e0b1\files\lib\std\fmt.zig:685:81: 0x7ff6c8fc3b71 in formatType__anon_18245 (zig-playground.exe.obj)
                try formatType(value[i], actual_fmt, options, writer, max_depth - 1);
                                                                                ^
C:\...\zig\0.14.0-dev.2384+cbc05e0b1\files\lib\std\fmt.zig:674:31: 0x7ff6c8fb8e0a in formatType__anon_16532 (zig-playground.exe.obj)
                try formatType(elem, actual_fmt, options, writer, max_depth - 1);
                              ^
C:\...\zig\0.14.0-dev.2384+cbc05e0b1\files\lib\std\fmt.zig:622:31: 0x7ff6c8fa9d59 in formatType__anon_14386 (zig-playground.exe.obj)
                try formatType(@field(value, f.name), ANY, options, writer, max_depth - 1);
                              ^
C:\...\zig\0.14.0-dev.2384+cbc05e0b1\files\lib\std\fmt.zig:622:31: 0x7ff6c8f928dc in formatType__anon_11624 (zig-playground.exe.obj)
                try formatType(@field(value, f.name), ANY, options, writer, max_depth - 1);
                              ^
C:\...\zig\0.14.0-dev.2384+cbc05e0b1\files\lib\std\fmt.zig:188:23: 0x7ff6c8f72807 in format__anon_2552 (zig-playground.exe.obj)
        try formatType(
                      ^
C:\...\zig\0.14.0-dev.2384+cbc05e0b1\files\lib\std\io\Writer.zig:24:26: 0x7ff6c8f71912 in print__anon_2338 (zig-playground.exe.obj)
    return std.fmt.format(self, format, args);
                         ^
C:\...\zig\0.14.0-dev.2384+cbc05e0b1\files\lib\std\debug.zig:98:27: 0x7ff6c8f71165 in print__anon_2085 (zig-playground.exe.obj)
    nosuspend stderr.print(fmt, args) catch return;
                          ^
C:\...\main.zig:23:20: 0x7ff6c8f7100e in main (zig-playground.exe.obj)
    std.debug.print("struct {}\n", .{m});

I believe it is because in formatType, the .vector branch doesn't check that max_depth == 0.

Expected Behavior

I expect output similar to
struct main.Struct{ .mat = main.Mat{ .values = { ... } } }

@christopherliu830 christopherliu830 added the bug Observed behavior contradicts documented or intended behavior label Jan 1, 2025
@Vexu Vexu added the standard library This issue involves writing Zig code for the standard library. label Jan 1, 2025
@Vexu Vexu added this to the 0.14.0 milestone Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants