Subject: [alpine-user] Bug in busybox's sort -s ?

From: Assaf Gordon <[email-masked]>
Date: Sun, 20 Aug 2017 20:11:42 -0600

Hello,

I encountered strange result with "sort -s" on Alpine 3.6.2.
Wanted to check with you before filing a bug:

The following two commands (with and without -s) give different
result on alpine linux 3.6.2/amd64,
withg 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

They give the same result (as they should) with
coreutil's, FreeBSD and OpenBSD's sort.

Strangely, I also get the correct same result
when building busybox on a Debian machine,
tried both the latest git and tag 1_26_2.

It's only on an Alpine VM that I get this discrepancy.

Any ideas?

Thanks!
 - assaf

---
Unsubscribe:  [email-masked]
Help:         [email-masked]
---

---

From: Achim <[email-masked]>
Date: Mon, 21 Aug 2017 08:26:34 +0200

Please check you environment: remove all LC_* variables and set LANG=C
(or unset LANG), then try again.

Just my 2 pence
Achim

---

---

From: Alexey Luchko <[email-masked]>
Date: Mon, 21 Aug 2017 12:41:46 +0300

https://git.busybox.net/busybox/tree/coreutils/sort.c#n486
It uses qsort() that is not stable by default.  It could have been
made stable by adding line number to the comparison key, however there
is no evidence of any attempt for it.
https://git.busybox.net/busybox/tree/coreutils/sort.c#n125

Regargs
Alex

---