diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2022-01-04 23:53:21 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2022-01-04 23:53:21 +0100 |
| commit | cc7d2e21780c28608b00a4faf0fed297527bcbf4 (patch) | |
| tree | e3fbe3c8461299d14687e490d1b70ea1b80879fd | |
| parent | dfd8aafcf59c88662516a534a4334b3f08f58c88 (diff) | |
| download | busybox-w32-cc7d2e21780c28608b00a4faf0fed297527bcbf4.tar.gz busybox-w32-cc7d2e21780c28608b00a4faf0fed297527bcbf4.tar.bz2 busybox-w32-cc7d2e21780c28608b00a4faf0fed297527bcbf4.zip | |
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>
| -rw-r--r-- | coreutils/sort.c | 4 | ||||
| -rwxr-xr-x | testsuite/sort.tests | 13 |
2 files changed, 16 insertions, 1 deletions
diff --git a/coreutils/sort.c b/coreutils/sort.c index 0cbb6f597..9ff777851 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c | |||
| @@ -380,7 +380,9 @@ static int compare_keys(const void *xarg, const void *yarg) | |||
| 380 | 380 | ||
| 381 | /* If x > y, 1, else -1 */ | 381 | /* If x > y, 1, else -1 */ |
| 382 | retval = (x32 > y32) * 2 - 1; | 382 | retval = (x32 > y32) * 2 - 1; |
| 383 | } else | 383 | /* Here, -r has no effect! */ |
| 384 | return retval; | ||
| 385 | } | ||
| 384 | if (!(option_mask32 & FLAG_no_tie_break)) { | 386 | if (!(option_mask32 & FLAG_no_tie_break)) { |
| 385 | /* fallback sort */ | 387 | /* fallback sort */ |
| 386 | flags = option_mask32; | 388 | flags = option_mask32; |
diff --git a/testsuite/sort.tests b/testsuite/sort.tests index c51a8e475..5375f93de 100755 --- a/testsuite/sort.tests +++ b/testsuite/sort.tests | |||
| @@ -175,6 +175,19 @@ testing "sort file in place" \ | |||
| 175 | 111 | 175 | 111 |
| 176 | " "" | 176 | " "" |
| 177 | 177 | ||
| 178 | testing "sort -sr (stable and reverse) does NOT reverse 'stable' ordering" \ | ||
| 179 | "sort -k2 -r -s input" "\ | ||
| 180 | b 2 | ||
| 181 | d 2 | ||
| 182 | a 1 | ||
| 183 | c 1 | ||
| 184 | " "\ | ||
| 185 | a 1 | ||
| 186 | b 2 | ||
| 187 | c 1 | ||
| 188 | d 2 | ||
| 189 | " "" | ||
| 190 | |||
| 178 | # testing "description" "command(s)" "result" "infile" "stdin" | 191 | # testing "description" "command(s)" "result" "infile" "stdin" |
| 179 | 192 | ||
| 180 | exit $FAILCOUNT | 193 | exit $FAILCOUNT |
