diff options
| author | Ali Ahmet Memis <ali@iusegentoo.com> | 2026-08-17 23:16:38 +0000 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2026-08-31 22:54:31 +0200 |
| commit | 74ac096e895acd6b02976bb010e9b3511234e899 (patch) | |
| tree | bc39de11c7dade32a681f1ea6bb530c38a8e3089 /shell/ash_test/ash-misc | |
| parent | 8f4dc3b40589107fdc84922c366bd4be4fc3e61d (diff) | |
| download | busybox-w32-busybox.tar.gz busybox-w32-busybox.tar.bz2 busybox-w32-busybox.zip | |
sort: compute -k END.ENDCHAR from the end field, not the line startbusybox
get_key() locates a key in two passes: j=0 walks to the start of the
START field, j=1 walks to the end of the END field. When END carries
an ENDCHAR (-kSTART,N.ENDCHAR), that char position is supposed to be
counted from the start of field N. Instead the code overwrote 'end'
with the raw parsed value, an offset from the very start of the line:
if (key->range[3]) {
end = key->range[3];
For END field 1 this happens to be the same thing, but for any later
field it is not. The result usually lands before 'start', which then
gets clamped to 'start', producing an empty key. Sort has an ASCII
whole-line fallback when keys tie, so it silently sorts by the whole
line instead of the requested key:
$ printf '%s\n' 'b:aa' 'a:ba' 'a:aa' | busybox sort -t : -k 2.1,2.1
a:aa
a:ba
b:aa
$ printf '%s\n' 'b:aa' 'a:ba' 'a:aa' | sort -t : -k 2.1,2.1
a:aa
b:aa
a:ba
Make the j=1 pass stop at the start of field N instead of its end when
ENDCHAR is given, one field-skip short of the usual pass, and add the
ENDCHAR offset from there. This mirrors how STARTCHAR is already
applied relative to the start of the START field. Verified against
several -k combinations (endchar past the field's own length, multiple
fields skipped, startchar and endchar together) matching GNU sort.
Add a regression test; the existing ENDCHAR test only exercises field
1, where the old absolute offset and the correct field-relative one
happen to coincide.
function old new delta
get_key 490 516 +26
Signed-off-by: Ali Ahmet Memis <ali@iusegentoo.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/ash_test/ash-misc')
0 files changed, 0 insertions, 0 deletions
