comparison arogue5/state.c @ 110:5f51f7d9805f

arogue5: fix some save/restore-related crashes. The save/restore code took the pointer intended as an argument for the doctor() daemon and wrote it to the savefile as an int. I don't know why it took so long to fail horribly. The problem has been avoided by replacing the value with &player when restoring. That seems to be the only argument ever actually used. The code also writes only four bytes for an unsigned long; if sizeof(long) == 8, it casts to unsigned int first. It failed to do the cast when reading back, with the result that four bytes were read and the other half of the number was effectively uninitialized. It apparently works now, but the save/restore code ought still to be regarded as decidedly unfortunate.
author John "Elwin" Edwards
date Mon, 06 Jan 2014 15:57:17 -0500
parents 09db0cf536af
children a5433ba4cabf
comparison
equal deleted inserted replaced
109:ec9db3bb6b0b 110:5f51f7d9805f
639 bytes[1] = buf[2]; 639 bytes[1] = buf[2];
640 bytes[0] = buf[3]; 640 bytes[0] = buf[3];
641 buf = bytes; 641 buf = bytes;
642 } 642 }
643 643
644 *i = *((unsigned long *) buf); 644 if ( (sizeof(long) == 8) && (sizeof(int) == 4) )
645 *i = *((unsigned int *) buf);
646 else
647 *i = *((unsigned long *) buf);
645 648
646 return(READSTAT); 649 return(READSTAT);
647 } 650 }
648 651
649 int 652 int
1513 default: d_list[i].d_func = NULL; 1516 default: d_list[i].d_func = NULL;
1514 break; 1517 break;
1515 } 1518 }
1516 1519
1517 rs_read_int(inf, &d_list[i].d_arg); 1520 rs_read_int(inf, &d_list[i].d_arg);
1521 if (func == 2)
1522 d_list[i].d_arg = &player;
1518 rs_read_int(inf, &d_list[i].d_time); 1523 rs_read_int(inf, &d_list[i].d_time);
1519 1524
1520 if (d_list[i].d_func == NULL) 1525 if (d_list[i].d_func == NULL)
1521 { 1526 {
1522 d_list[i].d_time = 0; 1527 d_list[i].d_time = 0;