comparison arogue5/daemon.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 f2951c4e28d9
children 56e748983fa8
comparison
equal deleted inserted replaced
113:aa582a02eb5d 114:a5433ba4cabf
85 85
86 /* 86 /*
87 * start_daemon: 87 * start_daemon:
88 * Start a daemon, takes a function. 88 * Start a daemon, takes a function.
89 */ 89 */
90 start_daemon(func, arg, type) 90 start_daemon(int (*func)(), void *arg, int type)
91 reg int arg, type, (*func)();
92 { 91 {
93 reg struct delayed_action *dev; 92 reg struct delayed_action *dev;
94 93
95 dev = d_slot(); 94 dev = d_slot();
96 if (dev != NULL) { 95 if (dev != NULL) {
120 if (i >= MAXDAEMONS) return; /* if not found, forget it */ 119 if (i >= MAXDAEMONS) return; /* if not found, forget it */
121 /* 120 /*
122 * Take it out of the list 121 * Take it out of the list
123 */ 122 */
124 dev->d_type = EMPTY; 123 dev->d_type = EMPTY;
125 dev->d_arg = 0; 124 dev->d_arg = NULL;
126 dev->d_func = NULL; 125 dev->d_func = NULL;
127 dev->d_time = 0; 126 dev->d_time = 0;
128 demoncnt -= 1; /* update count */ 127 demoncnt -= 1; /* update count */
129 } 128 }
130 129
153 152
154 /* 153 /*
155 * fuse: 154 * fuse:
156 * Start a fuse to go off in a certain number of turns 155 * Start a fuse to go off in a certain number of turns
157 */ 156 */
158 fuse(func, arg, time, type) 157 fuse(int (*func)(), void *arg, int time, int type)
159 reg int (*func)(), arg, time, type;
160 { 158 {
161 reg struct delayed_action *wire; 159 reg struct delayed_action *wire;
162 160
163 wire = f_slot(); 161 wire = f_slot();
164 if (wire != NULL) { 162 if (wire != NULL) {
197 195
198 if ((wire = find_slot(func)) == NULL) 196 if ((wire = find_slot(func)) == NULL)
199 return; 197 return;
200 wire->d_type = EMPTY; 198 wire->d_type = EMPTY;
201 wire->d_func = NULL; 199 wire->d_func = NULL;
202 wire->d_arg = 0; 200 wire->d_arg = NULL;
203 wire->d_time = 0; 201 wire->d_time = 0;
204 fusecnt -= 1; 202 fusecnt -= 1;
205 } 203 }
206 204
207 205