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.
This commit is contained in:
Paul Eggert 2017-03-07 21:23:08 -08:00
parent 1a6597660a
commit 1590127335
2 changed files with 8 additions and 4 deletions

View file

@ -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,

View file

@ -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.