------- Original Message -------
On Saturday, October 21st, 2023 at 05:22, Rob Landley <r...@landley.net> wrote:
> On 10/21/23 05:04, Rob Landley wrote:
> 
> > This guy went into detail, but I have not opened that particular can of 
> > worms yet:
> > 
> > http://databasearchitects.blogspot.com/2016/08/equivalence-of-unicode-strings-is.html
> 
> 
> Sigh:
> 
> https://www.unicode.org/reports/tr10/tr10-49.html
> 
> https://www.unicode.org/Public/UCA/latest/allkeys.txt
> 
> No. Not my problem. It looks like there's some code there already for 
> ascii-only
> [=blah=] (not that I've tried to work through what it's doing or why yet), and
> I'm pretty happy leaving it at that unless there's some libc plumbing I can
> defer this mess to...
> 
> Rob

Heya, I fixed a segfault in the -t option code (referencing toys.optargs[1] 
while not knowing if there _is_ toys.optargs[1])
and added a test case for it. Also changed the help text I added to swap SET2 
and SET1 (set1 is truncated with -t, not set2)

- Oliver Webb <aquahobby...@proton.me>
From 19e35c6a3c642969da64835016de2504c3b22ba6 Mon Sep 17 00:00:00 2001
From: Oliver Webb <aquahobby...@proton.me>
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.34.1

_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to