Mercurial > hg > early-roguelike
changeset 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 | 4a3f4729257c |
files | arogue5/save.c arogue7/save.c rogue4/extern.h rogue4/save.c srogue/io.c srogue/rip.c srogue/save.c |
diffstat | 7 files changed, 8 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/arogue5/save.c Fri Sep 15 19:57:54 2017 -0400 +++ b/arogue5/save.c Fri Sep 15 20:51:10 2017 -0400 @@ -21,6 +21,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <signal.h> +#include <time.h> #include "rogue.h" bool save_file(FILE *savef);
--- a/arogue7/save.c Fri Sep 15 19:57:54 2017 -0400 +++ b/arogue7/save.c Fri Sep 15 20:51:10 2017 -0400 @@ -24,6 +24,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <signal.h> +#include <time.h> #include "rogue.h" #include <fcntl.h> #include <errno.h> @@ -237,7 +238,7 @@ mpos = 0; msg(""); - /*msg("%s: %s", file, ctime(&sbuf2.st_mtime));*/ + msg("%s: %s", file, ctime(&sbuf2.st_mtime)); /* * defeat multiple restarting from the same place
--- a/rogue4/extern.h Fri Sep 15 19:57:54 2017 -0400 +++ b/rogue4/extern.h Fri Sep 15 20:51:10 2017 -0400 @@ -54,8 +54,6 @@ * Function types */ -char *ctime(), *getenv(); - void tstp(), endit(int); long lseek();
--- a/rogue4/save.c Fri Sep 15 19:57:54 2017 -0400 +++ b/rogue4/save.c Fri Sep 15 20:51:10 2017 -0400 @@ -16,6 +16,7 @@ #include <errno.h> #include <string.h> #include <stdlib.h> +#include <time.h> #define KERNEL #include <signal.h> #undef KERNEL
--- a/srogue/io.c Fri Sep 15 19:57:54 2017 -0400 +++ b/srogue/io.c Fri Sep 15 20:51:10 2017 -0400 @@ -268,24 +268,18 @@ #ifdef NEED_GETTIME #include <stdio.h> +#include <time.h> /* * gettime: * This routine returns the current time as a string */ -#ifdef ATT -#include <time.h> -#endif -#ifdef BSD -#include <sys/time.h> -#endif char * gettime() { register char *timeptr; - char *ctime(); - long int now, time(); + long int now; time(&now); /* get current time */ timeptr = ctime(&now); /* convert to string */
--- a/srogue/rip.c Fri Sep 15 19:57:54 2017 -0400 +++ b/srogue/rip.c Fri Sep 15 20:51:10 2017 -0400 @@ -18,6 +18,7 @@ #include <string.h> #include <sys/types.h> #include <fcntl.h> +#include <time.h> #include "rogue.h" #include "rogue.ext"
--- a/srogue/save.c Fri Sep 15 19:57:54 2017 -0400 +++ b/srogue/save.c Fri Sep 15 20:51:10 2017 -0400 @@ -22,6 +22,7 @@ #include <sys/types.h> #include <sys/stat.h> #include <signal.h> +#include <time.h> #include <errno.h> #if !defined(_WIN32) #include <unistd.h> @@ -30,7 +31,6 @@ #include "rogue.ext" EXTCHAR version[]; -EXTCHAR *ctime(); bool dosave(void); void save_file(FILE *savef);