You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am really unsure of why it crashes; I stumbled upon it during the Advent of Code. What I investigated:
Originally I allocated results and is_done dynamically, and it worked fine. It also works fine when only is_done is a literal.
Removing the results[last_4] += secret % 10; line removes the crash. However, debug printing showed that last_4 stays within the bounds of results as I expected.
The program seems to crash instantly; even a print at the very beginning does not appear.
I dared not remove more code when submitting the issue just in case, but the crash still happens even when changing next_secret to a dummy function.
For some reason, replacing all the usize with u32 also removed the crash.
Maybe there is a good reason for this, but I am not seeing it. I thought it might be something related to the size of the allocated array but this does not explain why it only happens in ReleaseFast mode.
Thanks in advance.
The text was updated successfully, but these errors were encountered:
thuiop
added
the
bug
Observed behavior contradicts documented or intended behavior
label
Jan 9, 2025
Without having looked at the code in detail: That's... a lot of data to put on the stack. Could well be a stack overflow. I suggest you try to move it to global variables and see if the issue still reproduces.
Without having looked at the code in detail: That's... a lot of data to put on the stack. Could well be a stack overflow. I suggest you try to move it to global variables and see if the issue still reproduces.
Indeed, moving them to global variables seems to solve the issue, so I guess it is indeed the size of the array. However, why does it work in Debug mode?
Zig Version
0.13.0
Steps to Reproduce and Observed Behavior
Compile the following code with -OReleaseFast to see it crashing
However, it does not crash when in Debug.
System: Nixos 24.05
Kernel: 6.6.41
Architecture: x86_64
Expected Behavior
I am really unsure of why it crashes; I stumbled upon it during the Advent of Code. What I investigated:
results
andis_done
dynamically, and it worked fine. It also works fine when onlyis_done
is a literal.results[last_4] += secret % 10;
line removes the crash. However, debug printing showed thatlast_4
stays within the bounds ofresults
as I expected.next_secret
to a dummy function.usize
withu32
also removed the crash.Maybe there is a good reason for this, but I am not seeing it. I thought it might be something related to the size of the allocated array but this does not explain why it only happens in ReleaseFast mode.
Thanks in advance.
The text was updated successfully, but these errors were encountered: