about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCarlos O'Donell <carlos@redhat.com>2023-05-17 09:16:41 -0400
committerCarlos O'Donell <carlos@redhat.com>2023-05-18 12:33:24 -0400
commitb0528456a606faf996ae8046512d623a6d22d0cc (patch)
treee95a8ae210bde6008a6d39db270e7209376821e8
parentc4098bc256a892aee214ec7c722a4a45f661a55c (diff)
downloadglibc-b0528456a606faf996ae8046512d623a6d22d0cc.tar.gz
glibc-b0528456a606faf996ae8046512d623a6d22d0cc.tar.xz
glibc-b0528456a606faf996ae8046512d623a6d22d0cc.zip
scripts: sort-makefile-lines.py
We must return < 0, 0, or > 0 as the result of the comparison function
for cmp_to_key() to work correctly across all comparisons.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
-rwxr-xr-xscripts/sort-makefile-lines.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/scripts/sort-makefile-lines.py b/scripts/sort-makefile-lines.py
index fd657df970..c0badebf8c 100755
--- a/scripts/sort-makefile-lines.py
+++ b/scripts/sort-makefile-lines.py
@@ -102,7 +102,10 @@ def glibc_makefile_numeric(string1, string2):
             # string1 and string2 both share a prefix and
             # have a numeric suffix that can be compared.
             # Sort order is based on the numeric suffix.
-            return int(var1.group(1)) > int(var2.group(1))
+            # If the suffix is the same return 0, otherwise
+            # > 0 for greater-than, and < 0 for less-than.
+            # This is equivalent to the numerical difference.
+            return int(var1.group(1)) - int(var2.group(1))
     # Default to strcoll.
     return locale.strcoll(string1, string2)