From ffe87454b93115be056a5ec99dd8300dafa9eb18 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 2 May 2021 15:27:50 -0700 Subject: bug: join-with segfault on character separators. * lib.c (join_with): Pass the correct onech array down to cat_str_init, rather than a null pointer. * tests/015/split.tl: New tests covering join and join-with. --- lib.c | 3 ++- tests/015/split.tl | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib.c b/lib.c index 95db82e4..7eb29a3e 100644 --- a/lib.c +++ b/lib.c @@ -5047,8 +5047,9 @@ val join_with(val sep, struct args *args) val iter; int more; struct cat_str cs; + wchar_t onech[] = wini(" "); - cat_str_init(&cs, sep, 0, self); + cat_str_init(&cs, sep, wref(onech), self); for (index = 0, iter = args->list, more = args_more_nozap(args, index, iter); more;) diff --git a/tests/015/split.tl b/tests/015/split.tl index ae77a642..e54092c5 100644 --- a/tests/015/split.tl +++ b/tests/015/split.tl @@ -194,3 +194,26 @@ (mtest (tok-str "abcacabcac" #/ab?/) #"ab a ab a" (tok-str "abcacabcac" #/ab?/ t) ("" "ab" "c" "a" "c" "ab" "c" "a" "c")) + +(mtest + (join) "" + (join "") "" + (join "" "") "" + (join #\a) "a" + (join "a") "a" + (join #\a "b") "ab" + (join "a" #\b) "ab" + (join #\a #\b) "ab" + (join "a" "b") "ab" + (join "a" "b" "cde") "abcde") + +(mtest + (join-with #\a) "" + (join-with #\a #\b) "b" + (join-with #\a "b") "b" + (join-with "a") "" + (join-with "a" #\b) "b" + (join-with "a" "b") "b" + (join-with "a" "b") "b" + (join-with "--" "b" "c" "d") "b--c--d" + (join-with #\- "b" "c" "d") "b-c-d") -- cgit v1.2.3