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
commitf5e806f2c119aea75870a525d224f75780144313 (patch)
tree3a0d3755462ad79e697dbf82ae290c11aba49b3b
parentb7e6cbab7c475f691f237eb688b5c65e2e19ae04 (diff)
downloadtxr-f5e806f2c119aea75870a525d224f75780144313.tar.gz
txr-f5e806f2c119aea75870a525d224f75780144313.tar.bz2
txr-f5e806f2c119aea75870a525d224f75780144313.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);