From 00931fee52a70cf445a63e273851b9b973a70a58 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 12 Feb 2015 06:56:14 -0800 Subject: * lib.c (lazy_appendv_func, lazy_appendv): Bugfix: append* was silently ignoring lists after the first atom, instead of throwing an error. Also, it was not detecting the case that the last argument is a list which should just be returned, and instead trying to find its tail in preparation for the next call to lazy_appendv_func, the consequences being runaway iteration over an infinite list. --- ChangeLog | 10 ++++++++++ lib.c | 12 ++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index a2bf3525..0897bd32 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2015-02-12 Kaz Kylheku + + * lib.c (lazy_appendv_func, lazy_appendv): Bugfix: append* + was silently ignoring lists after the first atom, instead of + throwing an error. Also, it was not detecting the case that + the last argument is a list which should just be returned, + and instead trying to find its tail in preparation for the + next call to lazy_appendv_func, the consequences being runaway + iteration over an infinite list. + 2015-02-10 Kaz Kylheku * eval.c (symacro_k, fun_k): New keyword variables. diff --git a/lib.c b/lib.c index 913d2b47..d4cc50cc 100644 --- a/lib.c +++ b/lib.c @@ -888,11 +888,15 @@ static val lazy_appendv_func(val env, val lcons) rplaca(lcons, last); - if (atom(nonempty)) { + if (nilp(lists)) { rplacd(lcons, nonempty); return nil; } + if (atom(nonempty)) + uw_throwf(error_s, lit("append*: cannot append to atom ~s"), + nonempty, nao); + rplacd(env, lists); { @@ -914,9 +918,13 @@ val lazy_appendv(val lists) break; } - if (atom(nonempty)) + if (nilp(lists)) return nonempty; + if (atom(nonempty)) + uw_throwf(error_s, lit("append*: cannot append to atom ~s"), + nonempty, nao); + { loc ptail = ltail(mkcloc(nonempty)); set(ptail, make_lazy_cons(func_f1(cons(car(deref(ptail)), lists), -- cgit v1.2.3