The right primative is used. I did look at bug #855 and checked if this was the case with the netserver code, however it's not.
Somehow (which I haven't worked out yet) Packet_scanf is over writing 2 ints. It's correctly writing to the first but then also writes 0 to the next 4 bytes. Leading to the crash.
The compiler puts player immediately after amt in memory. Thus player is being overwritten. By putting another int after amt, I've worked around this bug.
I have also checked the addresses with the intel OSX compiler and player is placed after amt but player is not over written in this case. Looks like it's a quirk in Packet_scanf with amd64 gcc.
This show the addresses of all the variables just before the scanf in drop_gold. You can see how my 3 padding variables sit around the amt variable. With the values ffffffff
- Code: Select all
DEBUG: drop gold ch aaa8068f amt aaa80678 player aaa80688 n aaa80684 pad aaa80674 aaa8067c aaa80680
DEBUG: drop gold pad ffffffff ffffffff ffffffff
The following are immediately after the va_arg calls in Packet_scanf, as you can see the address is the same as ch and amt. It does not write to aaa8067c.
- Code: Select all
char@aaa8068f
long@aaa80678
Here we can see the second padding variable @aaa8067c has been overwritten.
- Code: Select all
DEBUG: drop gold pad ffffffff 0 ffffffff
080211 131708 Player: You drop 1 pieces of gold.
This might be happening at other places in the code but it's just lucky that the overwritten variable isn't useful.
Mark