From 529a25a2eea4a6eea8c4e6420b15bd167d948a0a Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Tue, 16 Aug 2022 04:28:23 -0500 Subject: [PATCH] Sort -c reported line number was off by one. --- tests/sort.test | 3 ++- toys/posix/sort.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/sort.test b/tests/sort.test index 3e1e4ee0..d33a258d 100755 --- a/tests/sort.test +++ b/tests/sort.test @@ -104,7 +104,8 @@ toyonly testing "-kx" "sort -k1,1x" "3\na\n0c\n" "" "0c\na\n3\n" # "toy-2.37.tar.gz\ntoy-3.4.tar.gz\ntoy-3.12.tar.gz\ntoy-4.16-rc2.tar.gz\ntoy-4.16.tar.gz\n" "" \ # "toy-3.12.tar.gz\ntoy-2.37.tar.gz\ntoy-3.4.tar.gz\ntoy-4.16-rc2.tar.gz\ntoy-4.16.tar.gz" -testcmd "-c" "-uc |& grep -o [0-9]*" "3\n" "" "a\nb\nb\nc" +testcmd "-c" "-c |& grep -o [0-9]*" "3\n" "" "a\nb\na\nc" +testcmd "-uc" "-uc |& grep -o [0-9]*" "3\n" "" "a\nb\nb\nc" testcmd "-C 1" "-C || echo yes" "yes\n" "" "one\ntwo\nthree" testcmd "-C 2" "-C && echo yes" "yes\n" "" "a\nb\nc\n" diff --git a/toys/posix/sort.c b/toys/posix/sort.c index ec30c056..443ca3e8 100644 --- a/toys/posix/sort.c +++ b/toys/posix/sort.c @@ -287,7 +287,7 @@ static void sort_lines(char **pline, long len) if (TT.lines && compare_keys((void *)&TT.lines, &line)>-!!FLAG(u)) { toys.exitval = 1; if (FLAG(C)) xexit(); - error_exit("%s: Check line %u", TT.name, TT.linecount); + error_exit("%s: Check line %u", TT.name, TT.linecount+1); } free(TT.lines); TT.lines = (void *)line; -- 2.39.2