Skip to content

infinite print using warn on a recursive struct (sometimes) #1446

Closed
@cgag

Description

@cgag

code here: https://gist.github.com/cgag/04e2e921cb54474fcee0a6f20a1e3d98

So, it seems if I build this with build-exe, and run it It segfaults during the warn on the e1:

e1: Expr{ .Binary = Binary{ .left = Expr{ .Binary = Binary{ .left = Expr{ .[2]    17262 segmentation fault (core dumped)  ./main

If I build with release-fast, it prints e1 correctly, then basically prints a million recursive binary structs and segfaults:

ryzen ~ » zig build-exe --release-fast main.zig  && ./main
zig build-exe --release-fast main.zig  0.95s user 0.06s system 100% cpu 1.000 total
e1: Expr{ .Binary = Binary{ .left = Expr{ .Literal = Literal{ .String = left-value } }, .right = Expr{ .Literal = Literal{ .Number = 2.0e+01 } }, .token = PLUS } }
e: Expr{ .Binary = Binary{ .left = Expr{ .Binary = Binary{ .left = Expr{ .Binary = Binary{ .left = Expr{ .Binary = Binary{ .left = Expr{ .Binary = Binary{ .left = Expr{ .Binary = Binary{ .left = Expr{ .Binary = Binary{ .left =
 Expr{ .Binary = Binary{ .left = Expr{ .Binary = Binary{ .left = Expr{ .Binary = Binary{ .left = Expr{ .Binary = Binary{ .left = Expr{ .Binary = Binary{ .left = Expr{ .Binary = Binary{ .left = Expr{ .Binary = Binary{ .left = E
xpr{ .Binary = Binary{ .left = Expr{ .Binary = Binary{ .left = Expr{ .Binary = Binary{ .left = Expr{ .Binary = Binary{ .left = Expr{ .Binary = Binary{ .left = Expr{ .Binary = Binary{ .left = Expr{ .Binary = Binary{ .left = Exp
r{ .Binary = ... <segfault>

The only difference between the functions that produce the value that prints successfully (if built with release-fast), is the on that prints infinitely, is the first one is first rendered to a string by a function that doesn't modify the Expr.

Metadata

Metadata

Assignees

No one assigned

    Labels

    standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions