From 79825fd06cfd7140c8d6e25db1c0fdc5a42f6098 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 7 Mar 2017 21:23:08 -0800 Subject: [PATCH] min and max should not return markers Problem reported by Glenn Morris in: http://lists.gnu.org/archive/html/emacs-devel/2017-03/msg00147.html * src/data.c (minmax_driver): Convert any marker result to an integer, since some callers assume this. * test/src/data-tests.el (data-tests-max, data-tests-min): Test for this. --- src/data.c | 4 ++-- test/src/data-tests.el | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/data.c b/src/data.c index 29547d8..c480ed2 100644 --- a/src/data.c +++ b/src/data.c @@ -2972,9 +2972,9 @@ minmax_driver (ptrdiff_t nargs, Lisp_Object *args, if (argnum == 0 || !NILP (arithcompare (val, accum, comparison))) accum = val; else if (FLOATP (accum) && isnan (XFLOAT_DATA (accum))) - break; + return accum; } - return accum; + return MARKERP (accum) ? make_number (marker_position (accum)) : accum; } DEFUN ("max", Fmax, Smax, 1, MANY, 0, diff --git a/test/src/data-tests.el b/test/src/data-tests.el index 70ffdab..67d00a7 100644 --- a/test/src/data-tests.el +++ b/test/src/data-tests.el @@ -88,7 +88,9 @@ (should (= (1+ most-negative-fixnum) (max (float most-negative-fixnum) (1+ most-negative-fixnum)))) (should (= 8 (apply #'max '(3 8 3)))) - (should-error (max 9 8 'foo))) + (should-error (max 9 8 'foo)) + (should-error (max (make-marker))) + (should (eql 1 (max (point-min-marker) 1)))) (ert-deftest data-tests-min () (should-error (min)) @@ -98,7 +100,9 @@ (should (= most-positive-fixnum (min (+ 1.0 most-positive-fixnum) most-positive-fixnum))) (should (= 3 (apply #'min '(3 8 3)))) - (should-error (min 9 8 'foo))) + (should-error (min 9 8 'foo)) + (should-error (min (make-marker))) + (should (eql 1 (min (point-min-marker) 1)))) ;; Bool vector tests. Compactly represent bool vectors as hex ;; strings. -- 2.9.3