aboutsummaryrefslogtreecommitdiffstats
path: root/src/editfns.c
diff options
context:
space:
mode:
authorPaul Eggert2014-08-03 08:38:52 -0700
committerPaul Eggert2014-08-03 08:38:52 -0700
commit308cc448e5d6ffd44c7ff366a99d34bbfb0e8c4d (patch)
tree04e83c1f35b94135a52711a5934e752fffea5c3d /src/editfns.c
parent8f88f7d3c5da38cd2d781770b533dc6c93c52d59 (diff)
downloademacs-308cc448e5d6ffd44c7ff366a99d34bbfb0e8c4d.tar.gz
emacs-308cc448e5d6ffd44c7ff366a99d34bbfb0e8c4d.zip
Don't mishandle year-9999 dates.
* lisp/calendar/parse-time.el (parse-time-rules): Allow years up to most-positive-fixnum. * lisp/calendar/time-date.el (date-to-time): Pass "Specified time is not representable" errors through. * lisp/url/url-cookie.el (url-cookie-expired-p): Treat out-of-range expiration dates as if they were far in the future. * src/editfns.c (decode_time_components): Store an invalid timespec on overflow, instead of returning false, so that the caller can distinguish overflow from other errors. (lisp_time_argument, lisp_seconds_argument): If the time is out of range, signal a time overflow instead of an invalid time spec. * src/keyboard.c (decode_timer): Treat time overflow like other timespec errors. Fixes: debbugs:18176
Diffstat (limited to 'src/editfns.c')
-rw-r--r--src/editfns.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/editfns.c b/src/editfns.c
index e8d4478f2f6..f779bb9ebb6 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -1516,7 +1516,8 @@ disassemble_lisp_time (Lisp_Object specified_time, Lisp_Object *phigh,
1516 list, generate the corresponding time value. 1516 list, generate the corresponding time value.
1517 1517
1518 If RESULT is not null, store into *RESULT the converted time; 1518 If RESULT is not null, store into *RESULT the converted time;
1519 this can fail if the converted time does not fit into struct timespec. 1519 if the converted time does not fit into struct timespec,
1520 store an invalid timespec to indicate the overflow.
1520 If *DRESULT is not null, store into *DRESULT the number of 1521 If *DRESULT is not null, store into *DRESULT the number of
1521 seconds since the start of the POSIX Epoch. 1522 seconds since the start of the POSIX Epoch.
1522 1523
@@ -1529,7 +1530,7 @@ decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec,
1529 EMACS_INT hi, lo, us, ps; 1530 EMACS_INT hi, lo, us, ps;
1530 if (! (INTEGERP (high) && INTEGERP (low) 1531 if (! (INTEGERP (high) && INTEGERP (low)
1531 && INTEGERP (usec) && INTEGERP (psec))) 1532 && INTEGERP (usec) && INTEGERP (psec)))
1532 return 0; 1533 return false;
1533 hi = XINT (high); 1534 hi = XINT (high);
1534 lo = XINT (low); 1535 lo = XINT (low);
1535 us = XINT (usec); 1536 us = XINT (usec);
@@ -1555,16 +1556,13 @@ decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec,
1555 *result = make_timespec ((sec << 16) + lo, us * 1000 + ps / 1000); 1556 *result = make_timespec ((sec << 16) + lo, us * 1000 + ps / 1000);
1556 } 1557 }
1557 else 1558 else
1558 { 1559 *result = invalid_timespec ();
1559 /* Overflow in the highest-order component. */
1560 return 0;
1561 }
1562 } 1560 }
1563 1561
1564 if (dresult) 1562 if (dresult)
1565 *dresult = (us * 1e6 + ps) / 1e12 + lo + hi * 65536.0; 1563 *dresult = (us * 1e6 + ps) / 1e12 + lo + hi * 65536.0;
1566 1564
1567 return 1; 1565 return true;
1568} 1566}
1569 1567
1570/* Decode a Lisp list SPECIFIED_TIME that represents a time. 1568/* Decode a Lisp list SPECIFIED_TIME that represents a time.
@@ -1576,22 +1574,23 @@ decode_time_components (Lisp_Object high, Lisp_Object low, Lisp_Object usec,
1576struct timespec 1574struct timespec
1577lisp_time_argument (Lisp_Object specified_time) 1575lisp_time_argument (Lisp_Object specified_time)
1578{ 1576{
1579 struct timespec t;
1580 if (NILP (specified_time)) 1577 if (NILP (specified_time))
1581 t = current_timespec (); 1578 return current_timespec ();
1582 else 1579 else
1583 { 1580 {
1584 Lisp_Object high, low, usec, psec; 1581 Lisp_Object high, low, usec, psec;
1582 struct timespec t;
1585 if (! (disassemble_lisp_time (specified_time, &high, &low, &usec, &psec) 1583 if (! (disassemble_lisp_time (specified_time, &high, &low, &usec, &psec)
1586 && decode_time_components (high, low, usec, psec, &t, 0))) 1584 && decode_time_components (high, low, usec, psec, &t, 0)))
1587 error ("Invalid time specification"); 1585 error ("Invalid time specification");
1586 if (! timespec_valid_p (t))
1587 time_overflow ();
1588 return t;
1588 } 1589 }
1589 return t;
1590} 1590}
1591 1591
1592/* Like lisp_time_argument, except decode only the seconds part, 1592/* Like lisp_time_argument, except decode only the seconds part,
1593 do not allow out-of-range time stamps, do not check the subseconds part, 1593 and do not check the subseconds part. */
1594 and always round down. */
1595static time_t 1594static time_t
1596lisp_seconds_argument (Lisp_Object specified_time) 1595lisp_seconds_argument (Lisp_Object specified_time)
1597{ 1596{
@@ -1605,6 +1604,8 @@ lisp_seconds_argument (Lisp_Object specified_time)
1605 && decode_time_components (high, low, make_number (0), 1604 && decode_time_components (high, low, make_number (0),
1606 make_number (0), &t, 0))) 1605 make_number (0), &t, 0)))
1607 error ("Invalid time specification"); 1606 error ("Invalid time specification");
1607 if (! timespec_valid_p (t))
1608 time_overflow ();
1608 return t.tv_sec; 1609 return t.tv_sec;
1609 } 1610 }
1610} 1611}