Move explanations from ChangeLog to the source.

This commit is contained in:
Eli Zaretskii 2006-03-25 08:56:07 +00:00
parent 0f49150ef4
commit 71c3f28fb7
2 changed files with 16 additions and 16 deletions

View file

@ -1,22 +1,11 @@
2006-03-24 Paul Eggert <eggert@cs.ucla.edu>
* 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
<http://www.opengroup.org/austin/mailarchives/ag/msg09294.html>
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 <storm@cua.dk>

View file

@ -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
<http://www.opengroup.org/austin/mailarchives/ag/msg09294.html>
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");