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.
This commit is contained in:
John "Elwin" Edwards 2015-06-26 11:42:02 -04:00
parent c639303acf
commit 419a920e1d
2 changed files with 30 additions and 4 deletions

View file

@ -549,7 +549,10 @@ rs_read_long(int inf, long *i)
buf = bytes;
}
*i = *((long *) buf);
if (sizeof(long) == 8)
*i = *((int *) buf);
else
*i = *((long *) buf);
return(READSTAT);
}
@ -641,7 +644,10 @@ rs_read_ulong(int inf, unsigned long *i)
buf = bytes;
}
*i = *((unsigned long *) buf);
if ( (sizeof(long) == 8) && (sizeof(int) == 4) )
*i = *((unsigned int *) buf);
else
*i = *((unsigned long *) buf);
return(READSTAT);
}

View file

@ -201,9 +201,16 @@ rs_write_int(FILE *savef, int c)
rs_write_ulong(FILE *savef, unsigned long c)
{
unsigned int c2;
char bytes[4];
char *buf = (char *)&c;
if ( (sizeof(long) == 8) && (sizeof(int) == 4) )
{
c2 = c;
buf = (char *) &c2;
}
if (big_endian)
{
bytes[3] = buf[0];
@ -220,9 +227,16 @@ rs_write_ulong(FILE *savef, unsigned long c)
rs_write_long(FILE *savef, long c)
{
int c2;
char bytes[4];
char *buf = (char *)&c;
if ( (sizeof(long) == 8) && (sizeof(int) == 4) )
{
c2 = c;
buf = (char *) &c2;
}
if (big_endian)
{
bytes[3] = buf[0];
@ -312,7 +326,10 @@ rs_read_ulong(int inf, unsigned long *i)
buf = bytes;
}
*i = *((unsigned long *) buf);
if ( (sizeof(long) == 8) && (sizeof(int) == 4) )
*i = *((unsigned int *) buf);
else
*i = *((unsigned long *) buf);
return(READSTAT);
}
@ -333,7 +350,10 @@ rs_read_long(int inf, long *i)
buf = bytes;
}
*i = *((long *) buf);
if ( (sizeof(long) == 8) && (sizeof(int) == 4) )
*i = *((int *) buf);
else
*i = *((long *) buf);
return(READSTAT);
}