Mercurial > hg > early-roguelike
diff 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 |
line wrap: on
line diff
--- a/arogue7/state.c Fri Jun 26 11:32:37 2015 -0400 +++ b/arogue7/state.c Fri Jun 26 11:42:02 2015 -0400 @@ -549,7 +549,10 @@ buf = bytes; } - *i = *((long *) buf); + if (sizeof(long) == 8) + *i = *((int *) buf); + else + *i = *((long *) buf); return(READSTAT); } @@ -641,7 +644,10 @@ buf = bytes; } - *i = *((unsigned long *) buf); + if ( (sizeof(long) == 8) && (sizeof(int) == 4) ) + *i = *((unsigned int *) buf); + else + *i = *((unsigned long *) buf); return(READSTAT); }