sort: do not perform top level comparison if -k supplied with -c

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

sort: do not perform top level comparison if -k supplied with -c

Richard Ipsum-2
Hi,

I think there may be a bug in OpenBSD's sort utility.
The bug is that when -c is used in combination with a key field,
a "top level" sort is performed when the key field does not have
disorder. This differs from what might be expected and certainly from
what occurs with other versions of sort.

Given the input file 'unsorted_csv':

AAAA,aaaa,AAAA
AAAA,AAAA,AAAA
AAAA,bbbb,AAAA
AAAA,BBBB,AAAA
AAAA,cccc,AAAA
AAAA,CCCC,AAAA

On Linux:

$ sort -c -t , -k 2f unsorted_csv
$ echo $?
0

On OpenBSD:

$ sort -c -t , -k 2f unsorted_csv
sort: unsorted_csv:2: disorder: AAAA,AAAA,AAAA
$ echo $?
1

The patch below seems to fix this issue.

Thanks,
Richard

diff --git file.c file.c
index 9d84d7cb4f6..b6bbf1e2b4c 100644
--- file.c
+++ file.c
@@ -387,7 +387,8 @@ check(const char *fn)
  printf("; cmp1=%d", cmp);
 
  if (!cmp && sort_opts_vals.complex_sort &&
-    !(sort_opts_vals.uflag) && !(sort_opts_vals.sflag)) {
+    !(sort_opts_vals.uflag) && !(sort_opts_vals.sflag) &&
+    !(sort_opts_vals.kflag)) {
  cmp = top_level_str_coll(s2, s1);
  if (debug_sort)
  printf("; cmp2=%d", cmp);

Reply | Threaded
Open this post in threaded view
|

Re: sort: do not perform top level comparison if -k supplied with -c

Todd C. Miller-3
On Sat, 28 Dec 2019 18:26:38 +0100, Richard Ipsum wrote:

> I think there may be a bug in OpenBSD's sort utility.
> The bug is that when -c is used in combination with a key field,
> a "top level" sort is performed when the key field does not have
> disorder. This differs from what might be expected and certainly from
> what occurs with other versions of sort.

Thanks, committed.

 - todd