From d9793bee00aae304b1d7b550600bec7bdb601702 Mon Sep 17 00:00:00 2001 From: Oliver Webb Date: Mon, 23 Oct 2023 21:33:03 -0500 Subject: [PATCH] Fix tr -t no set2 segfault and help text --- tests/tr.test | 1 + toys/pending/tr.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/tr.test b/tests/tr.test index 9b3070cf..6d598bee 100755 --- a/tests/tr.test +++ b/tests/tr.test @@ -8,5 +8,6 @@ testing "" "tr 1 2" "223223223" "" "123123123" testing "-d" "tr -d 1" "232323" "" "123123123" testing "-s" "tr -s 1" "12223331222333" "" "111222333111222333" testing "-t" "tr -t 1234 567" "5674" "" "1234" +testing "-t one arg" "tr -t 1234" "1234" "" "1234" testing "no pathological flushing" "seq 10000000 | tr 1 2 > /dev/null" "" "" "" diff --git a/toys/pending/tr.c b/toys/pending/tr.c index bd2f0577..8e35fc99 100644 --- a/toys/pending/tr.c +++ b/toys/pending/tr.c @@ -18,7 +18,7 @@ config TR -c/-C Take complement of SET1 -d Delete input characters coded SET1 -s Squeeze multiple output characters of SET2 into one character - -t Truncate SET2 to length of SET1 + -t Truncate SET1 to length of SET2 */ #define FOR_tr @@ -225,7 +225,7 @@ void tr_main(void) for (; i < 256; i++) TT.map[i] = i; //init map set1 = expand_set(*toys.optargs, &TT.len1, - FLAG(t) ? strlen(toys.optargs[1]) : -1); + (FLAG(t) && toys.optargs[1]) ? strlen(toys.optargs[1]) : -1); if (FLAG(c)) do_complement(&set1); if (toys.optargs[1]) { if (!*toys.optargs[1]) error_exit("set2 can't be empty string"); -- 2.39.2