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

From: Dmitry Antipov <[email-masked]>
Date: Sat, 30 Aug 2014 10:55:17 +0400

On 08/30/2014 09:22 AM, Paul Eggert wrote:

> See, for example,
>
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42157
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51297

Very nice.  But couldn't we detect an improper comparison
function at runtime?  For example:

=== modified file 'src/fns.c'
--- src/fns.c   2014-08-29 19:18:06 +0000
+++ src/fns.c   2014-08-30 06:52:20 +0000
@@ -1933,6 +1933,8 @@
       preserve original order.  Pretty ugly but works.  */
    more = NILP (call2 (sort_vector_predicate, vp, vq));
    less = NILP (call2 (sort_vector_predicate, vq, vp));
+  if (!more && !less)
+    error ("Not an anti-symmetrical predicate in sort");
    return ((more && !less) ? 1
           : ((!more && less) ? -1
              : XSAVE_INTEGER (op, 0) - XSAVE_INTEGER (oq, 0)));

Dmitry