Mercurial > hg > early-roguelike
comparison arogue5/state.c @ 114:a5433ba4cabf
arogue5: fix some daemon-related pointer/int casting.
Daemons and fuses take a single argument, nominally an int but either
ignored or unsafely cast to a pointer. Its type has now been changed
to void*.
The save/restore code no longer tries to store this argument in the
savefile. For doctor(), this is not a problem, because player is the
only argument it is ever given as a daemon. However, alchemy() will
fail to do anything when passed NULL. Fixing this would be complicated
but possible.
Summary: the code is slightly safer, but alchemy jugs are guaranteed to
stop working after save and restore, instead of just extremely likely.
author | John "Elwin" Edwards |
---|---|
date | Fri, 28 Mar 2014 10:57:03 -0700 |
parents | 5f51f7d9805f |
children | 1cf517d5d2a8 |
comparison
equal
deleted
inserted
replaced
113:aa582a02eb5d | 114:a5433ba4cabf |
---|---|
1418 else | 1418 else |
1419 func = -1; | 1419 func = -1; |
1420 | 1420 |
1421 rs_write_int(savef, d_list[i].d_type); | 1421 rs_write_int(savef, d_list[i].d_type); |
1422 rs_write_int(savef, func); | 1422 rs_write_int(savef, func); |
1423 rs_write_int(savef, d_list[i].d_arg); | 1423 /* d_arg is a pointer and can't actually be saved and restored. */ |
1424 rs_write_int(savef, 0); | |
1424 rs_write_int(savef, d_list[i].d_time); | 1425 rs_write_int(savef, d_list[i].d_time); |
1425 } | 1426 } |
1426 | 1427 |
1427 return(WRITESTAT); | 1428 return(WRITESTAT); |
1428 } | 1429 } |
1515 case -1: | 1516 case -1: |
1516 default: d_list[i].d_func = NULL; | 1517 default: d_list[i].d_func = NULL; |
1517 break; | 1518 break; |
1518 } | 1519 } |
1519 | 1520 |
1520 rs_read_int(inf, &d_list[i].d_arg); | 1521 rs_read_int(inf, &dummy); |
1522 d_list[i].d_arg = NULL; | |
1521 if (func == 2) | 1523 if (func == 2) |
1522 d_list[i].d_arg = &player; | 1524 d_list[i].d_arg = &player; |
1523 rs_read_int(inf, &d_list[i].d_time); | 1525 rs_read_int(inf, &d_list[i].d_time); |
1524 | 1526 |
1525 if (d_list[i].d_func == NULL) | 1527 if (d_list[i].d_func == NULL) |
1526 { | 1528 { |
1527 d_list[i].d_time = 0; | 1529 d_list[i].d_time = 0; |
1528 d_list[i].d_arg = 0; | |
1529 d_list[i].d_type = 0; | 1530 d_list[i].d_type = 0; |
1530 } | 1531 } |
1531 } | 1532 } |
1532 | 1533 |
1533 return(READSTAT); | 1534 return(READSTAT); |