sort: fix sort -s -u, closes 14871

function                                             old     new   delta
sort_main                                            851     856      +5

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2022-07-29 16:40:00 +02:00
parent 00f2a35b83
commit 5479c435fd
2 changed files with 15 additions and 4 deletions

View File

@ -652,11 +652,12 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
/* Handle -u */ /* Handle -u */
if (option_mask32 & FLAG_u) { if (option_mask32 & FLAG_u) {
int j = 0; int j = 0;
/* coreutils 6.3 drop lines for which only key is the same /* coreutils 6.3 drop lines for which only key is the same:
* -- disabling last-resort compare, or else compare_keys() * - disabling last-resort compare, or else compare_keys()
* will be the same only for completely identical lines. * will be the same only for completely identical lines
* - disabling -s (same reasons)
*/ */
option_mask32 |= FLAG_no_tie_break; option_mask32 = (option_mask32 | FLAG_no_tie_break) & (~FLAG_s);
for (i = 1; i < linecount; i++) { for (i = 1; i < linecount; i++) {
if (compare_keys(&lines[j], &lines[i]) == 0) if (compare_keys(&lines[j], &lines[i]) == 0)
free(lines[i]); free(lines[i]);

View File

@ -230,4 +230,14 @@ testing "sort -k2,2M" \
3 March 3 March
" "" " ""
testing "sort -s -u" \
"sort -s -u -k 2 input" "\
z a
z b
" "\
z b
a b
z a
a a" ""
exit $FAILCOUNT exit $FAILCOUNT