From 9b3459ca129ffe680f8e8c8caeb00167c7180a22 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 2 Dec 2021 07:42:45 -0800 Subject: 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. --- lib.c | 4 ++++ tests/012/seq.tl | 3 +++ 2 files changed, 7 insertions(+) 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) -- cgit v1.2.3