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:
parent
c639303acf
commit
419a920e1d
2 changed files with 30 additions and 4 deletions
|
|
@ -549,6 +549,9 @@ rs_read_long(int inf, long *i)
|
||||||
buf = bytes;
|
buf = bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sizeof(long) == 8)
|
||||||
|
*i = *((int *) buf);
|
||||||
|
else
|
||||||
*i = *((long *) buf);
|
*i = *((long *) buf);
|
||||||
|
|
||||||
return(READSTAT);
|
return(READSTAT);
|
||||||
|
|
@ -641,6 +644,9 @@ rs_read_ulong(int inf, unsigned long *i)
|
||||||
buf = bytes;
|
buf = bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( (sizeof(long) == 8) && (sizeof(int) == 4) )
|
||||||
|
*i = *((unsigned int *) buf);
|
||||||
|
else
|
||||||
*i = *((unsigned long *) buf);
|
*i = *((unsigned long *) buf);
|
||||||
|
|
||||||
return(READSTAT);
|
return(READSTAT);
|
||||||
|
|
|
||||||
|
|
@ -201,9 +201,16 @@ rs_write_int(FILE *savef, int c)
|
||||||
|
|
||||||
rs_write_ulong(FILE *savef, unsigned long c)
|
rs_write_ulong(FILE *savef, unsigned long c)
|
||||||
{
|
{
|
||||||
|
unsigned int c2;
|
||||||
char bytes[4];
|
char bytes[4];
|
||||||
char *buf = (char *)&c;
|
char *buf = (char *)&c;
|
||||||
|
|
||||||
|
if ( (sizeof(long) == 8) && (sizeof(int) == 4) )
|
||||||
|
{
|
||||||
|
c2 = c;
|
||||||
|
buf = (char *) &c2;
|
||||||
|
}
|
||||||
|
|
||||||
if (big_endian)
|
if (big_endian)
|
||||||
{
|
{
|
||||||
bytes[3] = buf[0];
|
bytes[3] = buf[0];
|
||||||
|
|
@ -220,9 +227,16 @@ rs_write_ulong(FILE *savef, unsigned long c)
|
||||||
|
|
||||||
rs_write_long(FILE *savef, long c)
|
rs_write_long(FILE *savef, long c)
|
||||||
{
|
{
|
||||||
|
int c2;
|
||||||
char bytes[4];
|
char bytes[4];
|
||||||
char *buf = (char *)&c;
|
char *buf = (char *)&c;
|
||||||
|
|
||||||
|
if ( (sizeof(long) == 8) && (sizeof(int) == 4) )
|
||||||
|
{
|
||||||
|
c2 = c;
|
||||||
|
buf = (char *) &c2;
|
||||||
|
}
|
||||||
|
|
||||||
if (big_endian)
|
if (big_endian)
|
||||||
{
|
{
|
||||||
bytes[3] = buf[0];
|
bytes[3] = buf[0];
|
||||||
|
|
@ -312,6 +326,9 @@ rs_read_ulong(int inf, unsigned long *i)
|
||||||
buf = bytes;
|
buf = bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( (sizeof(long) == 8) && (sizeof(int) == 4) )
|
||||||
|
*i = *((unsigned int *) buf);
|
||||||
|
else
|
||||||
*i = *((unsigned long *) buf);
|
*i = *((unsigned long *) buf);
|
||||||
return(READSTAT);
|
return(READSTAT);
|
||||||
}
|
}
|
||||||
|
|
@ -333,6 +350,9 @@ rs_read_long(int inf, long *i)
|
||||||
buf = bytes;
|
buf = bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( (sizeof(long) == 8) && (sizeof(int) == 4) )
|
||||||
|
*i = *((int *) buf);
|
||||||
|
else
|
||||||
*i = *((long *) buf);
|
*i = *((long *) buf);
|
||||||
return(READSTAT);
|
return(READSTAT);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue