- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add Compiler Error when returning pointer to stack variable #2646
Labels
Milestone
Comments
Related: #2301 |
This was referenced Oct 29, 2022
Closely related: #5725 |
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm new to zig and low level programming in general. Naturally when I encountered the code for setting up an allocater I tried to encapsulate it.
I tried to (in retrospect naively) create a struct to take care of the repetition in my tests:
When using this I get a segfault though.
In #zig @shawnl was helpful enough to explain the issue. The allocators are created on the stack of the
init
function and so the pointers to them that are set on the struct are invalid once theinit
function returns.I am opening this issue because @shawnl claims there may be a way to figure out when such pointers are created and survive beyond the lifetime of the stack variables and for the compiler to raise an error.
The text was updated successfully, but these errors were encountered: