Recent comments
-
2 days 15 hours ago
-
2 days 15 hours ago
-
3 days 15 hours ago
-
2 weeks 3 days ago
-
3 weeks 2 days ago
-
3 weeks 3 days ago
-
3 weeks 3 days ago
-
1 month 1 day ago
-
1 month 1 day ago
-
1 month 1 week ago
-
1 month 1 week ago
-
1 month 2 weeks ago
Follow us
Elk News - the email newsletter
Subscribe to the Elk RSS feed, including blog posts, pictures and videos.
Titles only
Full content
Comments aren't included in these feeds. For them you can click the RSS icon in the Recent Comments box.
Our videos at
YouTube
Add new reply
Now this one was tricky!
My code crashed with a segmentation fault - it appeared to be somewhat random; sometimes I could run my algorithm 1000 times all fine, and sometimes it crashed on 400th run. And a segfault is typically caused somewhere earlier in the code, so you can't find the cause by spotting the crashing point. I had to experiment with commenting out different parts of the code until I got it narrowed down to a single line:
weatheryear[i].temp=currtemp+0.5;
At first I thought that i is somehow running outside the array, but no - it was always within 0..364 (I'm precalculating a temperature value for each day of a year). Then what? currtemp is a float. And temp is a signed char, which is enough to store values ranging from -50 ... +50. And currtemp is always inside this range,too. Can you spot the bug?
Well, I don't know if this is documented somewhere, but this was remedied by changing temp to be a signed int. So, somehow, in some cases, converting a float to a signed char causes a memory leak. I didn't know that!