summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-11-27 06:40:08 -0800
committerKaz Kylheku <kaz@kylheku.com>2018-11-27 06:40:08 -0800
commit7996c9220ec33a5c9c4d3acdade3b4b93f7dd87f (patch)
tree3a0d3755462ad79e697dbf82ae290c11aba49b3b
parent6eed5ead43aa206fa6213c3e7069f5d3fe601c66 (diff)
downloadtxr-7996c9220ec33a5c9c4d3acdade3b4b93f7dd87f.tar.gz
txr-7996c9220ec33a5c9c4d3acdade3b4b93f7dd87f.tar.bz2
txr-7996c9220ec33a5c9c4d3acdade3b4b93f7dd87f.zip
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.
-rw-r--r--eval.c5
1 files 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);