From: Kento L. <me...@kl...> - 2012-04-10 05:43:28
|
Hey all, I was bored so I cross-compiled TuxMath for Windows, but the game kept quitting when I tried to start a mission. Seg Fault! http://pastie.org/3759844 After mucking around in gdb, I found and fixed the problem... I attached the diff git gave me since I don't have write access to the git repo (diff for the head of the tuxmath t4k-0.1.1 branch). I haven't used C since high-school, so it might not be the ideal way... Basically the problem is the MC_MathGame instance's question pointers are never explicitly initialized to null. The contents of the memory block malloc returns are implementation dependent, and on Windows apparently that can mean a block of memory filled with 0xbaadf00d [1]. Since MC_Initialize doesn't initialize the question pointers, we're left with a bunch of not-null pointers to invalid memory... obviously a problem. So, the simple fix is to explicitly initialize them to null. Note: this isn't currently a problem on linux - which zeroes memory that wasn't previously allocated to the program (for security) - nor is there a problem with the Windows executable on the site - which was built back when MC_MathQuestion were globals that were explicitly initialized to null. Cheers! Kento Locatelli [1] https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_debug_values <https://en.wikipedia.org/wiki/Magic_number_%28programming%29#Magic_debug_values> |