Mercurial > hg > early-roguelike
comparison arogue7/state.c @ 166:9b5f1e6aa35a
arogue7, xrogue: fix uninitialized variables when restoring.
The save and restore code assumed sizeof(long) == 4, which is not the
case on x64. Reading only 4 bytes from the savefile left the others
uninitialized, which led to problems like billions of experience points
or gold pieces.
author | John "Elwin" Edwards |
---|---|
date | Fri, 26 Jun 2015 11:42:02 -0400 |
parents | 1af259ac4ed2 |
children | aa8e1fc62926 |
comparison
equal
deleted
inserted
replaced
165:2d94c32a709e | 166:9b5f1e6aa35a |
---|---|
547 bytes[1] = buf[2]; | 547 bytes[1] = buf[2]; |
548 bytes[0] = buf[3]; | 548 bytes[0] = buf[3]; |
549 buf = bytes; | 549 buf = bytes; |
550 } | 550 } |
551 | 551 |
552 *i = *((long *) buf); | 552 if (sizeof(long) == 8) |
553 *i = *((int *) buf); | |
554 else | |
555 *i = *((long *) buf); | |
553 | 556 |
554 return(READSTAT); | 557 return(READSTAT); |
555 } | 558 } |
556 | 559 |
557 int | 560 int |
639 bytes[1] = buf[2]; | 642 bytes[1] = buf[2]; |
640 bytes[0] = buf[3]; | 643 bytes[0] = buf[3]; |
641 buf = bytes; | 644 buf = bytes; |
642 } | 645 } |
643 | 646 |
644 *i = *((unsigned long *) buf); | 647 if ( (sizeof(long) == 8) && (sizeof(int) == 4) ) |
648 *i = *((unsigned int *) buf); | |
649 else | |
650 *i = *((unsigned long *) buf); | |
645 | 651 |
646 return(READSTAT); | 652 return(READSTAT); |
647 } | 653 } |
648 | 654 |
649 int | 655 int |