aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert1998-09-06 15:49:17 +0000
committerPaul Eggert1998-09-06 15:49:17 +0000
commit177ea5f115f2a11066c6ac2569eaf0e2f1461f49 (patch)
treef75a90785c22b0d8a199edf10ed5c7a2d859f1f7 /src
parentbf6ab66c9adfcc1136f6ef343185039d531d5b6d (diff)
downloademacs-177ea5f115f2a11066c6ac2569eaf0e2f1461f49.tar.gz
emacs-177ea5f115f2a11066c6ac2569eaf0e2f1461f49.zip
(Fformat_time_string, Fdecode_time, Fcurrent_time_zone):
Don't assume that localtime and gmtime return non-NULL.
Diffstat (limited to 'src')
-rw-r--r--src/editfns.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/editfns.c b/src/editfns.c
index 31324cfde6f..0e4f7ce540e 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -905,6 +905,7 @@ DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string, 1, 3, 0,
905{ 905{
906 time_t value; 906 time_t value;
907 int size; 907 int size;
908 struct tm *tm;
908 909
909 CHECK_STRING (format_string, 1); 910 CHECK_STRING (format_string, 1);
910 911
@@ -914,6 +915,10 @@ DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string, 1, 3, 0,
914 /* This is probably enough. */ 915 /* This is probably enough. */
915 size = STRING_BYTES (XSTRING (format_string)) * 6 + 50; 916 size = STRING_BYTES (XSTRING (format_string)) * 6 + 50;
916 917
918 tm = NILP (universal) ? localtime (&value) : gmtime (&value);
919 if (! tm)
920 error ("Specified time is not representable");
921
917 while (1) 922 while (1)
918 { 923 {
919 char *buf = (char *) alloca (size + 1); 924 char *buf = (char *) alloca (size + 1);
@@ -921,15 +926,13 @@ DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string, 1, 3, 0,
921 926
922 buf[0] = '\1'; 927 buf[0] = '\1';
923 result = emacs_strftime (buf, size, XSTRING (format_string)->data, 928 result = emacs_strftime (buf, size, XSTRING (format_string)->data,
924 (NILP (universal) ? localtime (&value) 929 tm);
925 : gmtime (&value)));
926 if ((result > 0 && result < size) || (result == 0 && buf[0] == '\0')) 930 if ((result > 0 && result < size) || (result == 0 && buf[0] == '\0'))
927 return build_string (buf); 931 return build_string (buf);
928 932
929 /* If buffer was too small, make it bigger and try again. */ 933 /* If buffer was too small, make it bigger and try again. */
930 result = emacs_strftime (NULL, 0x7fffffff, XSTRING (format_string)->data, 934 result = emacs_strftime (NULL, 0x7fffffff, XSTRING (format_string)->data,
931 (NILP (universal) ? localtime (&value) 935 tm);
932 : gmtime (&value)));
933 size = result + 1; 936 size = result + 1;
934 } 937 }
935} 938}
@@ -959,6 +962,8 @@ ZONE is an integer indicating the number of seconds east of Greenwich.\n\
959 error ("Invalid time specification"); 962 error ("Invalid time specification");
960 963
961 decoded_time = localtime (&time_spec); 964 decoded_time = localtime (&time_spec);
965 if (! decoded_time)
966 error ("Specified time is not representable");
962 XSETFASTINT (list_args[0], decoded_time->tm_sec); 967 XSETFASTINT (list_args[0], decoded_time->tm_sec);
963 XSETFASTINT (list_args[1], decoded_time->tm_min); 968 XSETFASTINT (list_args[1], decoded_time->tm_min);
964 XSETFASTINT (list_args[2], decoded_time->tm_hour); 969 XSETFASTINT (list_args[2], decoded_time->tm_hour);
@@ -1143,18 +1148,15 @@ the data it can't find.")
1143{ 1148{
1144 time_t value; 1149 time_t value;
1145 struct tm *t; 1150 struct tm *t;
1151 struct tm gmt;
1146 1152
1147 if (lisp_time_argument (specified_time, &value) 1153 if (lisp_time_argument (specified_time, &value)
1148 && (t = gmtime (&value)) != 0) 1154 && (t = gmtime (&value)) != 0
1155 && (gmt = *t, t = localtime (&value)) != 0)
1149 { 1156 {
1150 struct tm gmt; 1157 int offset = tm_diff (t, &gmt);
1151 int offset; 1158 char *s = 0;
1152 char *s, buf[6]; 1159 char buf[6];
1153
1154 gmt = *t; /* Make a copy, in case localtime modifies *t. */
1155 t = localtime (&value);
1156 offset = tm_diff (t, &gmt);
1157 s = 0;
1158#ifdef HAVE_TM_ZONE 1160#ifdef HAVE_TM_ZONE
1159 if (t->tm_zone) 1161 if (t->tm_zone)
1160 s = (char *)t->tm_zone; 1162 s = (char *)t->tm_zone;