Bug 10671 - sort -s is not stable
Summary: sort -s is not stable
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: All Linux
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-23 20:23 UTC by 9qq3ip+an9ogcgv8nr9g
Modified: 2018-02-21 19:12 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description 9qq3ip+an9ogcgv8nr9g 2018-01-23 20:23:07 UTC
Someone on the Alpine Linux users mailing list observed that "sort -s" is not stable as intended.
  "
   The following two commands (with and without -s) give different
   result on alpine linux 3.6.2/amd64,
   with busybox v1.26.2 (2017-08-03 13:08:12 GMT):

     $ printf "a X 1\nA X 2\nA x 5\n" | sort -k1,1
     A X 2
     A x 5
     a X 1

     $ printf "a X 1\nA X 2\nA x 5\n" | sort -k1,1 -s
     A x 5
     A X 2
     a X 1
  "

Another user observed that sort.c uses qsort(), which is documented as not stable, and suggested adding the line number as an additional (internal) key to make it so.

Here are the mailing list posts:
  https://lists.alpinelinux.org/alpine-user/0178.html
  https://lists.alpinelinux.org/alpine-user/0180.html
Comment 1 Denys Vlasenko 2018-02-21 19:12:10 UTC
commit 7d285c78a35b1e745f7c6f27e31d73677ad2943a
Author: Denys Vlasenko <vda.linux@googlemail.com>
Date:   Wed Feb 21 20:08:54 2018 +0100

    sort: fix -s. Closes 10671