From: Eli Zaretskii Date: Sat, 25 Mar 2006 08:56:07 +0000 (+0000) Subject: Move explanations from ChangeLog to the source. X-Git-Tag: emacs-pretest-22.0.90~3431 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=71c3f28fb7d178e546ce05290ccc4927041dc342;p=emacs.git Move explanations from ChangeLog to the source. --- diff --git a/src/ChangeLog b/src/ChangeLog index ccc1f3923c4..15267b42d45 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,22 +1,11 @@ 2006-03-24 Paul Eggert - * editfns.c: Do not use ctime, since it has undefined behavior - with out-of-range time stamps. This fixes a bug where - (current-time-string '(2814749767106 0)) would make Emacs dump - core on 64-bit Solaris 8. The fix is to use localtime+asctime - (checking for in-range results) instead of ctime. Please see - - for more details about this portability problem. - (TM_YEAR_BASE): Move up, so the changes below can use it. + * editfns.c (TM_YEAR_BASE): Move up, so the changes below can use it. (Fdecode_time, Fencode_time): Use TM_YEAR_BASE instead of 1900. - (Fdecode_time): Cast tm_year to EMACS_INT, to avoid overflow when - int is narrower than EMACS_INT. - (Fcurrent_time_string): As with Fformat_time_string, report an - invalid time specification if the argument is invalid. Also, - check for out-of-range time stamps; this prevents a buffer overrun - that causes Emacs to dump core on 64-bit Solaris sparc, and it - preserves the historic behavior of always returning a fixed-size - string. + (Fdecode_time): Cast tm_year to EMACS_INT. + (Fcurrent_time_string): Report an invalid time specification if + the argument is invalid. Also, check for out-of-range time + stamps. 2006-03-24 Kim F. Storm diff --git a/src/editfns.c b/src/editfns.c index c4f8b95d810..888bbe3062b 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -1724,6 +1724,8 @@ DOW and ZONE.) */) XSETFASTINT (list_args[2], decoded_time->tm_hour); XSETFASTINT (list_args[3], decoded_time->tm_mday); XSETFASTINT (list_args[4], decoded_time->tm_mon + 1); + /* On 64-bit machines an int is narrower than EMACS_INT, thus the + cast below avoids overflow in int arithmetics. */ XSETINT (list_args[5], TM_YEAR_BASE + (EMACS_INT) decoded_time->tm_year); XSETFASTINT (list_args[6], decoded_time->tm_wday); list_args[7] = (decoded_time->tm_isdst)? Qt : Qnil; @@ -1851,7 +1853,16 @@ but this is considered obsolete. */) if (! lisp_time_argument (specified_time, &value, NULL)) error ("Invalid time specification"); + /* Do not use ctime, since it has undefined behavior with + out-of-range time stamps. This avoids a core dump triggered by + (current-time-string '(2814749767106 0)) on 64-bit Solaris 8. See + + for more details about this portability problem. */ tm = localtime (&value); + /* Checking for out-of-range time stamps avoids buffer overruns that + cause core dump on some systems (e.g., 64-bit Solaris), and also + preserves the historic behavior of always returning a fixed-size + 24-character string. */ if (! (tm && -999 - TM_YEAR_BASE <= tm->tm_year && tm->tm_year <= 9999 - TM_YEAR_BASE)) error ("Specified time is not representable");