Subject: Re: bug#18361: New 'sort' implementation can crash Emacs

From: Dmitry Antipov <[email-masked]>
Date: Sat, 30 Aug 2014 09:07:46 +0400

On 08/30/2014 03:07 AM, Paul Eggert wrote:

> Sure, a comparison function that returns a new random value every
> time you call it.  Such a function is most likely not well formed
> that is, it most likely does not define a total order.

If an undefined behavior doesn't cause crash, I don't see a problem
if this is well-documented (probably in lispref).

I gave this function a solid run on GNU/Linux (glibc 2.18) and FreeBSD
10.0, and was unable to crash:

(defun sort-run ()
   (interactive)
   (let* ((max 1000000)
          (size 1000)
          (p (make-progress-reporter "Sorted: " 0 max)))
     (dotimes (loops max)
       (let ((v (make-vector size 0)))
         (dotimes (i size) (aset v i (% (random) (* size 2))))
         (sort v (lambda (x y) (random)))
         (progress-reporter-update p loops)))
     (progress-reporter-done p)))

I don't have any reasons to not trust in your experience, but I'm
really curious to look at the real example crashing qsort(_r) due
to ill-formed comparison function.

Dmitry