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

function                                             old     new   delta
compare_keys                                         818     820      +2

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2022-01-04 23:53:21 +01:00
parent dfd8aafcf5
commit cc7d2e2178
2 changed files with 16 additions and 1 deletions

View File

@ -380,7 +380,9 @@ static int compare_keys(const void *xarg, const void *yarg)
/* If x > y, 1, else -1 */ /* If x > y, 1, else -1 */
retval = (x32 > y32) * 2 - 1; retval = (x32 > y32) * 2 - 1;
} else /* Here, -r has no effect! */
return retval;
}
if (!(option_mask32 & FLAG_no_tie_break)) { if (!(option_mask32 & FLAG_no_tie_break)) {
/* fallback sort */ /* fallback sort */
flags = option_mask32; flags = option_mask32;

View File

@ -175,6 +175,19 @@ testing "sort file in place" \
111 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" # testing "description" "command(s)" "result" "infile" "stdin"
exit $FAILCOUNT exit $FAILCOUNT