/* When combining components, require LOW to be an integer,
as otherwise it would be a pain to add up times. */
- if (! FIXNUMP (low))
+ if (! INTEGERP (low))
return 0;
}
- else if (FIXNUMP (specified_time))
+ else if (INTEGERP (specified_time))
len = 2;
*phigh = high;
Lisp_Object psec,
struct lisp_time *result, double *dresult)
{
- EMACS_INT hi, lo, us, ps;
+ EMACS_INT hi, us, ps;
+ intmax_t lo;
if (! (FIXNUMP (high)
&& FIXNUMP (usec) && FIXNUMP (psec)))
return 0;
- if (! FIXNUMP (low))
+ if (! INTEGERP (low))
{
if (FLOATP (low))
{
}
hi = XFIXNUM (high);
- lo = XFIXNUM (low);
+ if (! integer_to_intmax (low, &lo))
+ return -1;
us = XFIXNUM (usec);
ps = XFIXNUM (psec);
each overflow into the next higher-order component. */
us += ps / 1000000 - (ps % 1000000 < 0);
lo += us / 1000000 - (us % 1000000 < 0);
- hi += lo >> LO_TIME_BITS;
+ if (INT_ADD_WRAPV (lo >> LO_TIME_BITS, hi, &hi))
+ return -1;
ps = ps % 1000000 + 1000000 * (ps % 1000000 < 0);
us = us % 1000000 + 1000000 * (us % 1000000 < 0);
lo &= (1 << LO_TIME_BITS) - 1;
(format-time-string "%Y-%m-%d %H:%M:%S.%3N %z" nil
(concat (make-string 2048 ?X) "0")))))
+(defun editfns-tests--have-leap-seconds ()
+ (string-equal (format-time-string "%Y-%m-%d %H:%M:%S" 78796800 t)
+ "1972-06-30 23:59:60"))
+
+(ert-deftest format-time-string-with-bignum-on-32-bit ()
+ (should (or (string-equal
+ (format-time-string "%Y-%m-%d %H:%M:%S" (- (ash 1 31) 3600) t)
+ "2038-01-19 02:14:08")
+ (editfns-tests--have-leap-seconds))))
+
(ert-deftest format-with-field ()
(should (equal (format "First argument %2$s, then %3$s, then %1$s" 1 2 3)
"First argument 2, then 3, then 1"))