changeset 23198:dddce768cf7a

(Fformat_time_string, Fdecode_time, Fcurrent_time_zone): Don't assume that localtime and gmtime return non-NULL.
author Paul Eggert <eggert@twinsun.com>
date Sun, 06 Sep 1998 15:49:17 +0000
parents 0d3baa5514b7
children a6233ddd1a27
files src/editfns.c
diffstat 1 files changed, 15 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/editfns.c	Sun Sep 06 14:40:21 1998 +0000
+++ b/src/editfns.c	Sun Sep 06 15:49:17 1998 +0000
@@ -905,6 +905,7 @@
 {
   time_t value;
   int size;
+  struct tm *tm;
 
   CHECK_STRING (format_string, 1);
 
@@ -914,6 +915,10 @@
   /* This is probably enough.  */
   size = STRING_BYTES (XSTRING (format_string)) * 6 + 50;
 
+  tm = NILP (universal) ? localtime (&value) : gmtime (&value);
+  if (! tm)
+    error ("Specified time is not representable");
+
   while (1)
     {
       char *buf = (char *) alloca (size + 1);
@@ -921,15 +926,13 @@
 
       buf[0] = '\1';
       result = emacs_strftime (buf, size, XSTRING (format_string)->data,
-			       (NILP (universal) ? localtime (&value)
-				: gmtime (&value)));
+			       tm);
       if ((result > 0 && result < size) || (result == 0 && buf[0] == '\0'))
 	return build_string (buf);
 
       /* If buffer was too small, make it bigger and try again.  */
       result = emacs_strftime (NULL, 0x7fffffff, XSTRING (format_string)->data,
-			       (NILP (universal) ? localtime (&value)
-				: gmtime (&value)));
+			       tm);
       size = result + 1;
     }
 }
@@ -959,6 +962,8 @@
     error ("Invalid time specification");
 
   decoded_time = localtime (&time_spec);
+  if (! decoded_time)
+    error ("Specified time is not representable");
   XSETFASTINT (list_args[0], decoded_time->tm_sec);
   XSETFASTINT (list_args[1], decoded_time->tm_min);
   XSETFASTINT (list_args[2], decoded_time->tm_hour);
@@ -1143,18 +1148,15 @@
 {
   time_t value;
   struct tm *t;
+  struct tm gmt;
 
   if (lisp_time_argument (specified_time, &value)
-      && (t = gmtime (&value)) != 0)
+      && (t = gmtime (&value)) != 0
+      && (gmt = *t, t = localtime (&value)) != 0)
     {
-      struct tm gmt;
-      int offset;
-      char *s, buf[6];
-
-      gmt = *t;		/* Make a copy, in case localtime modifies *t.  */
-      t = localtime (&value);
-      offset = tm_diff (t, &gmt);
-      s = 0;
+      int offset = tm_diff (t, &gmt);
+      char *s = 0;
+      char buf[6];
 #ifdef HAVE_TM_ZONE
       if (t->tm_zone)
 	s = (char *)t->tm_zone;