aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2019-08-19 18:02:59 -0700
committerPaul Eggert2019-08-19 18:05:15 -0700
commit2197ea89bf5afabc4c52a6499b13e92ae6621554 (patch)
tree642c9ebf5c962305fedf69d4f14b95e3a8d8532d
parent50dc4ca8d02a466a7236765edf83ae7cfb02d74c (diff)
downloademacs-2197ea89bf5afabc4c52a6499b13e92ae6621554.tar.gz
emacs-2197ea89bf5afabc4c52a6499b13e92ae6621554.zip
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.
-rw-r--r--src/timefns.c6
-rw-r--r--test/src/timefns-tests.el4
2 files changed, 7 insertions, 3 deletions
diff --git a/src/timefns.c b/src/timefns.c
index 3948f873354..2d545a4f905 100644
--- a/src/timefns.c
+++ b/src/timefns.c
@@ -1035,12 +1035,12 @@ time_arith (Lisp_Object a, Lisp_Object b, bool subtract)
1035 double db = XFLOAT_DATA (Ffloat_time (b)); 1035 double db = XFLOAT_DATA (Ffloat_time (b));
1036 return make_float (subtract ? da - db : da + db); 1036 return make_float (subtract ? da - db : da + db);
1037 } 1037 }
1038 if (FLOATP (b) && !isfinite (XFLOAT_DATA (b)))
1039 return subtract ? make_float (-XFLOAT_DATA (b)) : b;
1040
1041 enum timeform aform, bform; 1038 enum timeform aform, bform;
1042 struct lisp_time ta = lisp_time_struct (a, &aform); 1039 struct lisp_time ta = lisp_time_struct (a, &aform);
1043 1040
1041 if (FLOATP (b) && !isfinite (XFLOAT_DATA (b)))
1042 return subtract ? make_float (-XFLOAT_DATA (b)) : b;
1043
1044 /* Subtract nil from nil correctly, and handle other eq values 1044 /* Subtract nil from nil correctly, and handle other eq values
1045 quicker while we're at it. Compare here rather than earlier, to 1045 quicker while we're at it. Compare here rather than earlier, to
1046 handle NaNs and check formats. */ 1046 handle NaNs and check formats. */
diff --git a/test/src/timefns-tests.el b/test/src/timefns-tests.el
index 13ab7d83c3e..a30b2de3a5b 100644
--- a/test/src/timefns-tests.el
+++ b/test/src/timefns-tests.el
@@ -136,6 +136,10 @@
136 (cons (1+ most-positive-fixnum) 1000000000000) 136 (cons (1+ most-positive-fixnum) 1000000000000)
137 (cons 1000000000000 (1+ most-positive-fixnum))))) 137 (cons 1000000000000 (1+ most-positive-fixnum)))))
138 (dolist (a time-values) 138 (dolist (a time-values)
139 (should-error (time-add a 'ouch))
140 (should-error (time-add 'ouch a))
141 (should-error (time-subtract a 'ouch))
142 (should-error (time-subtract 'ouch a))
139 (dolist (b time-values) 143 (dolist (b time-values)
140 (let ((aa (time-subtract (time-add a b) b))) 144 (let ((aa (time-subtract (time-add a b) b)))
141 (should (or (time-equal-p a aa) (and (floatp aa) (isnan aa))))) 145 (should (or (time-equal-p a aa) (and (floatp aa) (isnan aa)))))