]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix value< string comparison ungoodthink
authorMattias Engdegård <mattiase@acm.org>
Sun, 28 Apr 2024 21:17:48 +0000 (23:17 +0200)
committerEshel Yaron <me@eshelyaron.com>
Mon, 29 Apr 2024 19:48:05 +0000 (21:48 +0200)
* src/fns.c (string_cmp): Fix bad comparisons for certain strings.
This only affected `value<` for aggregates, not `string<`.
* test/src/fns-tests.el (fns-value<-ordered): Add test cases.

(cherry picked from commit 9b1e44c7fb5281688488ec077c048e268b716ad2)

src/fns.c
test/src/fns-tests.el

index 5cdd7e67f31907b11307b9d0153a609b95e6e34c..d4ba060188985ec9cb699f3fc079c3367378bbd7 100644 (file)
--- a/src/fns.c
+++ b/src/fns.c
@@ -481,7 +481,7 @@ string_cmp (Lisp_Object string1, Lisp_Object string2)
       int d = memcmp (SSDATA (string1), SSDATA (string2), n);
       if (d)
        return d;
-      return n < SCHARS (string2) ? -1 : n > SCHARS (string2);
+      return n < SCHARS (string2) ? -1 : n < SCHARS (string1);
     }
   else if (STRING_MULTIBYTE (string1) && STRING_MULTIBYTE (string2))
     {
@@ -515,7 +515,7 @@ string_cmp (Lisp_Object string1, Lisp_Object string2)
 
       if (b >= nb)
        /* One string is a prefix of the other.  */
-       return b < nb2 ? -1 : b > nb2;
+       return b < nb2 ? -1 : b < nb1;
 
       /* Now back up to the start of the differing characters:
         it's the last byte not having the bit pattern 10xxxxxx.  */
@@ -540,7 +540,7 @@ string_cmp (Lisp_Object string1, Lisp_Object string2)
          if (c1 != c2)
            return c1 < c2 ? -1 : 1;
        }
-      return i1 < SCHARS (string2) ? -1 : i1 > SCHARS (string2);
+      return i1 < SCHARS (string2) ? -1 : i1 < SCHARS (string1);
     }
   else
     {
@@ -553,7 +553,7 @@ string_cmp (Lisp_Object string1, Lisp_Object string2)
          if (c1 != c2)
            return c1 < c2 ? -1 : 1;
        }
-      return i1 < SCHARS (string2) ? -1 : i1 > SCHARS (string2);
+      return i1 < SCHARS (string2) ? -1 : i1 < SCHARS (string1);
     }
 }
 
index 068daf893f13e062776f5f42c261aaad436df112..a73a7a42f26e776a36054889c3ada3e637d144d4 100644 (file)
                    ;; strings
                    ("" . "a") ("a" . "b") ("A" . "a") ("abc" . "abd")
                    ("b" . "ba")
+                   ;; strings again, but in a context where 3-way comparison
+                   ;; matters
+                   (("" . 2) . ("a" . 1))
+                   (("å" . 2) . ("åü" . 1))
+                   (("a" . 2) . ("aå" . 1))
+                   (("\x80" . 2) . ("\x80å" . 1))
 
                    ;; lists
                    ((1 2 3) . (2 3 4)) ((2) . (2 1)) (() . (0))