aboutsummaryrefslogtreecommitdiff
path: root/testsuite/false
diff options
context:
space:
mode:
authorAli Ahmet Memis <ali@iusegentoo.com>2026-08-17 23:16:38 +0000
committerDenys Vlasenko <vda.linux@googlemail.com>2026-08-31 22:54:31 +0200
commit74ac096e895acd6b02976bb010e9b3511234e899 (patch)
treebc39de11c7dade32a681f1ea6bb530c38a8e3089 /testsuite/false
parent8f4dc3b40589107fdc84922c366bd4be4fc3e61d (diff)
downloadbusybox-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 'testsuite/false')
0 files changed, 0 insertions, 0 deletions