As a bit of background for the problem, I'm trying to loop through a list of PXmlNodes and extract the info from them.
The code that is having the problem:
echo(len(xml.findAll("item")))
for i in 0..high(xml.findAll("item")):
echo(i)
watches[i] = parseRSS(xml.findAll("item")[i])
echo(i)
watches is an array, and parseRSS is a function for getting information out of the XML and returning it as a custom type.
When the program is run, the following is output:
5
0
0
1
1
2
2
3
3
4
Segmentation fault (core dumped)
So it runs up to the fifth item, but then segfaults.
What's causing this, and how would I change the code to avoid this?
Thanks in advance for any help.
Sorry, when I wrote that I was tired, I'll try to do better. :p
The array has enough space, I made sure to check that.
Here's the full code: http://pastebin.com/dMC88txS
Note that the output is slightly different now, but it's the same problem:
4
0
0
1
1
2
2
3
3
Segmentation fault (core dumped)
This isn't due to changes I made in the program, but rather with changes in the data.
As for the stack trace, I'm afraid that I have really no experience with debuggers and no idea what to do. I'll go off and RTFM and edit later if I can figure it out. :p
You don't have to do anything to get a stack trace. However in your case you corrupted the stack so no stack trace works.
The problem is that due to a regression the compiler currently doesn't complain about the array with dynamic bounds that you use; arrays with dynamic bounds are not supported at all and your code shouldn't compile. You need to use a seq instead and either add to it or initialize it via var s = newSeq[YourType](YourSize). Then your program shouldn't crash anymore.