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

Segfault with too deep recursion #620

Closed
michelboaventura opened this issue May 4, 2015 · 2 comments
Closed

Segfault with too deep recursion #620

michelboaventura opened this issue May 4, 2015 · 2 comments

Comments

@michelboaventura
Copy link

This code:

require "big_int"                                                        

def fib(n)                                                               
  n > 1 ? n * fib(n - 1) : n                                             
end                                                                      

fib(100_000.to_big_i) 

Just gives a segfault. Reducing the value to 1000 solves. Compiling it with -d and running in gdb gives:

Starting program: /tmp/test
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7ffff3649700 (LWP 3833)]
[New Thread 0x7ffff3e4a700 (LWP 3832)]
[New Thread 0x7ffff464b700 (LWP 3831)]
[New Thread 0x7ffff4e4c700 (LWP 3830)]
[New Thread 0x7ffff564d700 (LWP 3829)]
[New Thread 0x7ffff5e4e700 (LWP 3828)]
[New Thread 0x7ffff664f700 (LWP 3827)]

Program received signal SIGSEGV, Segmentation fault.
0x0000000000401991 in __crystal_realloc ()

Not very useful. Running on valgrind gives a LOT of messages related with GC_* functions and this one, which may be the cause of segfault:

==3255== Stack overflow in thread 1: can't grow stack to 0xffe801c48

So I think Crystal isn't checking if it can allocate more memory on the stack. The same code on ruby gives:

test.cr:4:in `fib': stack level too deep (SystemStackError)
@jhass
Copy link
Member

jhass commented May 4, 2015

This is essentially a duplicate of #271

@michelboaventura
Copy link
Author

Hum, sorry about that. I should have looked before posting. Closing it now, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants