-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
large array on stack leads to segmentation fault #109533
Comments
What would you like to happen? |
Run and terminate. |
The stack normally has a size of ~1-2MB and you're trying to allocate an array of 40MB, of course it will overflow. Note that if you do stack overflow, you're guaranteed to segfault. The compiler inserts checks to ensure you don't skip guard pages, so the stack overflow has no risk to corrupt the memory of the rest of the program. If you really need values this big on the stack you can use a crate like stacker to grow it to match your needs. |
This is rust intentionally checking for stack overflow, as it guarantees safety for that. The segfault is just the way the current implementation happens to be enforcing that safety, since terminating the process is sound. If you want that much contiguous memory, you want a fn main() {
let a: Vec<i32> = vec![10; 10_000_000];
} |
The following program compiles but seg faults
It appears to be running out of stack space.
The text was updated successfully, but these errors were encountered: