aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1997-07-29 02:29:32 +0000
committerRichard M. Stallman1997-07-29 02:29:32 +0000
commitbfbcc5eed0a53ef546ff422212114bb48677aeff (patch)
treeb9f5922c3b457d2fc1efc5957b4eb6d754fa61e7
parent9a2fe7b2040ff4736f731ba546b15de3d9db82e1 (diff)
downloademacs-bfbcc5eed0a53ef546ff422212114bb48677aeff.tar.gz
emacs-bfbcc5eed0a53ef546ff422212114bb48677aeff.zip
(Fformat_time_string): Don't hang if strftime produces
an empty string. Fix arguments of second call to strftime. Remove check for result being negative, this cannot happen.
-rw-r--r--src/editfns.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/editfns.c b/src/editfns.c
index fa4f486c699..e49f53ff6b3 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -874,16 +874,15 @@ DEFUN ("format-time-string", Fformat_time_string, Sformat_time_string, 1, 3, 0,
874 char *buf = (char *) alloca (size + 1); 874 char *buf = (char *) alloca (size + 1);
875 int result; 875 int result;
876 876
877 buf[0] = '\1';
877 result = emacs_strftime (buf, size, XSTRING (format_string)->data, 878 result = emacs_strftime (buf, size, XSTRING (format_string)->data,
878 (NILP (universal) ? localtime (&value) 879 (NILP (universal) ? localtime (&value)
879 : gmtime (&value))); 880 : gmtime (&value)));
880 if (result > 0 && result < size) 881 if ((result > 0 && result < size) || (result == 0 && buf[0] == '\0'))
881 return build_string (buf); 882 return build_string (buf);
882 if (result < 0)
883 error ("Invalid time format specification");
884 883
885 /* If buffer was too small, make it bigger and try again. */ 884 /* If buffer was too small, make it bigger and try again. */
886 result = emacs_strftime (buf, 0, XSTRING (format_string)->data, 885 result = emacs_strftime (NULL, 0x7fffffff, XSTRING (format_string)->data,
887 (NILP (universal) ? localtime (&value) 886 (NILP (universal) ? localtime (&value)
888 : gmtime (&value))); 887 : gmtime (&value)));
889 size = result + 1; 888 size = result + 1;