emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 2197ea8 1/2: Fix time-add/time-sub validity checkin


From: Paul Eggert
Subject: [Emacs-diffs] master 2197ea8 1/2: Fix time-add/time-sub validity checking
Date: Mon, 19 Aug 2019 21:05:22 -0400 (EDT)

branch: master
commit 2197ea89bf5afabc4c52a6499b13e92ae6621554
Author: Paul Eggert <address@hidden>
Commit: Paul Eggert <address@hidden>

    Fix time-add/time-sub validity checking
    
    * src/timefns.c (time_arith): Check the first arg for
    validity even if the second arg is not finite.
    * test/src/timefns-tests.el (time-arith-tests): Test this.
---
 src/timefns.c             | 6 +++---
 test/src/timefns-tests.el | 4 ++++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/timefns.c b/src/timefns.c
index 3948f87..2d545a4 100644
--- a/src/timefns.c
+++ b/src/timefns.c
@@ -1035,12 +1035,12 @@ time_arith (Lisp_Object a, Lisp_Object b, bool subtract)
       double db = XFLOAT_DATA (Ffloat_time (b));
       return make_float (subtract ? da - db : da + db);
     }
-  if (FLOATP (b) && !isfinite (XFLOAT_DATA (b)))
-    return subtract ? make_float (-XFLOAT_DATA (b)) : b;
-
   enum timeform aform, bform;
   struct lisp_time ta = lisp_time_struct (a, &aform);
 
+  if (FLOATP (b) && !isfinite (XFLOAT_DATA (b)))
+    return subtract ? make_float (-XFLOAT_DATA (b)) : b;
+
   /* Subtract nil from nil correctly, and handle other eq values
      quicker while we're at it.  Compare here rather than earlier, to
      handle NaNs and check formats.  */
diff --git a/test/src/timefns-tests.el b/test/src/timefns-tests.el
index 13ab7d8..a30b2de 100644
--- a/test/src/timefns-tests.el
+++ b/test/src/timefns-tests.el
@@ -136,6 +136,10 @@
                           (cons (1+ most-positive-fixnum) 1000000000000)
                           (cons 1000000000000 (1+ most-positive-fixnum)))))
     (dolist (a time-values)
+      (should-error (time-add a 'ouch))
+      (should-error (time-add 'ouch a))
+      (should-error (time-subtract a 'ouch))
+      (should-error (time-subtract 'ouch a))
       (dolist (b time-values)
        (let ((aa (time-subtract (time-add a b) b)))
          (should (or (time-equal-p a aa) (and (floatp aa) (isnan aa)))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]