From 7996c9220ec33a5c9c4d3acdade3b4b93f7dd87f Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 27 Nov 2018 06:40:08 -0800 Subject: case macros: bugfix empty case. * eval.c (me_case): When there are no keys, then it is logically true that all keys are integer, and the hash table logic kicks in. The minkey and maxkey variables are supposed to be calculated as zero in that case, but the empty test is bungled since nkeys doesn't test false when it is zero. We end up with minkey and maxkey containing nil which get passed to the minus function. And so, here we fix the empty test. --- eval.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/eval.c b/eval.c index 0dc68559..5f7ee78d 100644 --- a/eval.c +++ b/eval.c @@ -4001,8 +4001,9 @@ static val me_case(val form, val menv) val minmax = cons(nil, nil); val nkeys = (maphash(func_f2(minmax, hash_min_max), hash), (hash_count(hash))); - val minkey = if3(nkeys, car(minmax), zero); - val maxkey = if3(nkeys, cdr(minmax), zero); + val empty = zerop(nkeys); + val minkey = if3(empty, zero, car(minmax)); + val maxkey = if3(empty, zero, cdr(minmax)); val i, range = minus(maxkey, minkey); val swres = gensym(lit("swres-")); val uniq = list(quote_s, make_sym(lit("nohit")), nao); -- cgit v1.2.3