comparison srogue/io.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 94a0d9dd5ce1
children e52a8a7ad4c5
comparison
equal deleted inserted replaced
279:d3968e9cb98d 280:70aa5808c782
266 continue; 266 continue;
267 } 267 }
268 268
269 #ifdef NEED_GETTIME 269 #ifdef NEED_GETTIME
270 #include <stdio.h> 270 #include <stdio.h>
271 #include <time.h>
271 272
272 /* 273 /*
273 * gettime: 274 * gettime:
274 * This routine returns the current time as a string 275 * This routine returns the current time as a string
275 */ 276 */
276 #ifdef ATT
277 #include <time.h>
278 #endif
279 #ifdef BSD
280 #include <sys/time.h>
281 #endif
282 277
283 char * 278 char *
284 gettime() 279 gettime()
285 { 280 {
286 register char *timeptr; 281 register char *timeptr;
287 char *ctime(); 282 long int now;
288 long int now, time();
289 283
290 time(&now); /* get current time */ 284 time(&now); /* get current time */
291 timeptr = ctime(&now); /* convert to string */ 285 timeptr = ctime(&now); /* convert to string */
292 return timeptr; /* return the string */ 286 return timeptr; /* return the string */
293 } 287 }