← Commit list

cc7d2e217

Denys Vlasenko
Denys Vlasenko
2022-01-04
SUCCESS Duration: 151s

Subject

sort: fix -s -r interaction: 'stable' order is not affected by -r

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

coreutils/sort.c+3 -1
@@ -380,7 +380,9 @@ static int compare_keys(const void *xarg, const void *yarg)
/* If x > y, 1, else -1 */
retval = (x32 > y32) * 2 - 1;
- } else
+ /* Here, -r has no effect! */
+ return retval;
+ }
if (!(option_mask32 & FLAG_no_tie_break)) {
/* fallback sort */
flags = option_mask32;
testsuite/sort.tests+13 -0
@@ -175,6 +175,19 @@ testing "sort file in place" \
111
" ""
+testing "sort -sr (stable and reverse) does NOT reverse 'stable' ordering" \
+"sort -k2 -r -s input" "\
+b 2
+d 2
+a 1
+c 1
+" "\
+a 1
+b 2
+c 1
+d 2
+" ""
+
# testing "description" "command(s)" "result" "infile" "stdin"
exit $FAILCOUNT