comparison arogue7/save.c @ 280:70aa5808c782

Fix potential segfaults at restore related to ctime(). In some games, restore() passes the result of ctime() to mvprintw() or some other variadic message-formatting function. If ctime() has not been declared properly, its return type is inferred to be int instead of char *. This does not cause a warning because the compiler does not know the correct type of variadic arguments. On platforms where ints and pointers are not the same size, this can, probably depending on alignment, result in a segfault that is not easy to trace. Including time.h fixes the problem. Some games manually declared ctime() and avoided the bug. These declarations have also been replaced with the include.
author John "Elwin" Edwards
date Fri, 15 Sep 2017 20:51:10 -0400
parents d3968e9cb98d
children
comparison
equal deleted inserted replaced
279:d3968e9cb98d 280:70aa5808c782
22 #include <stdlib.h> 22 #include <stdlib.h>
23 #include <string.h> 23 #include <string.h>
24 #include <sys/types.h> 24 #include <sys/types.h>
25 #include <sys/stat.h> 25 #include <sys/stat.h>
26 #include <signal.h> 26 #include <signal.h>
27 #include <time.h>
27 #include "rogue.h" 28 #include "rogue.h"
28 #include <fcntl.h> 29 #include <fcntl.h>
29 #include <errno.h> 30 #include <errno.h>
30 #include "mach_dep.h" 31 #include "mach_dep.h"
31 #ifdef PC7300 32 #ifdef PC7300
235 if (cols > 85) cols = 85; 236 if (cols > 85) cols = 85;
236 if (lines > 24) lines = 24; 237 if (lines > 24) lines = 24;
237 238
238 mpos = 0; 239 mpos = 0;
239 msg(""); 240 msg("");
240 /*msg("%s: %s", file, ctime(&sbuf2.st_mtime));*/ 241 msg("%s: %s", file, ctime(&sbuf2.st_mtime));
241 242
242 /* 243 /*
243 * defeat multiple restarting from the same place 244 * defeat multiple restarting from the same place
244 */ 245 */
245 if (!wizard && md_unlink_open_file(file, inf) < 0) { 246 if (!wizard && md_unlink_open_file(file, inf) < 0) {