views:

146

answers:

2

Someone please see my code at this link for input taken from this file( 2.2 mb file). This produces seg fault. By gdb, it shows seg fault in _vfprintf_r(). But when I comment line 41 and uncomment 38 (a null statement), there is no segmentation fault. line no 41 is just print statement. Someone please help. I am frustated and wasted a day in debugging. The output is written into result.txt file.

+4  A: 

You have a stack overflow. That's right, a Stack Overflow. I was able to reproduce by doing ulimit -s 1024. You need to not recurse so deeply, or you need to increase your stack size.

Matt
How to increase the stack size? But you did not get the error, u wrote in comment.
avd
Its a simple dfs on around 200000 vertices. The file specifies the graph. I have to submit it to online judge. How to do it?
avd
I didn't initially get the error. I lowered the stack size available and was able to reproduce the error. You can try ulimit -s <value> (my system defaults to 8192) to try and solve the issue, but I'm not sure if cygwin supports setting the stack size. A stack size of 2048 did not generate the error.
Matt
So if I run on linux system, then I wont get error?
avd
Most likely yes.
Matt
Thank you Matt and all others for looking at this problem. I will try on linux and then update.
avd
"That's right, a Stack Overflow." -- I tried searching to find what was so funny about that, but I got a Stack Overflow.
Windows programmer
Ya it runs on linux perfectly.
avd
A: 

As Matt answered, you're running out of stack. Add /STACK:amount to reserve in bytes,amount to initially commit in bytes to your link.exe command line.

Make sure both numbers are multiples of 4096, which is the default page size on windows IIRC.

JimR