summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-12-02 07:42:45 -0800
committerKaz Kylheku <kaz@kylheku.com>2021-12-02 07:42:45 -0800
commit4607f369cd3a7fb2af110d195752952b1a158569 (patch)
treedc823ad21d5bde3b8853cc6c487f7f678f4b0df7
parent7a94f17375a6fdf8a23ad9421f1f3580bc49eaa0 (diff)
downloadtxr-4607f369cd3a7fb2af110d195752952b1a158569.tar.gz
txr-4607f369cd3a7fb2af110d195752952b1a158569.tar.bz2
txr-4607f369cd3a7fb2af110d195752952b1a158569.zip
tuples: check length argument.
* lib.c (tuples): Check that n argument giving tuple size is a is a positive integer. * tests/012/seql.tl: Test case added.
-rw-r--r--lib.c4
-rw-r--r--tests/012/seq.tl3
2 files changed, 7 insertions, 0 deletions
diff --git a/lib.c b/lib.c
index 0fdc8ef0..7f797bb1 100644
--- a/lib.c
+++ b/lib.c
@@ -3575,8 +3575,12 @@ static val tuples_func(val n, val lcons)
val tuples(val n, val seq, val fill)
{
+ val self = lit("tuples");
seq = nullify(seq);
+ if (!plusp(n) || !integerp(n))
+ uw_throwf(error_s, lit("~a: positive integer required, not ~s"), self, n, nao);
+
if (!seq)
return nil;
diff --git a/tests/012/seq.tl b/tests/012/seq.tl
index d434ad52..d27adcef 100644
--- a/tests/012/seq.tl
+++ b/tests/012/seq.tl
@@ -212,3 +212,6 @@
[separate chr-isalpha "a1b2c3d4"] ("abcd" "1234")
[separate chrp "a1b2c3d4"] ("a1b2c3d4" "")
[separate integerp "a1b2c3d4"] ("" "a1b2c3d4"))
+
+(mtest
+ (tuples 0 '(1 2 3)) :error)