tisp

tiny lisp
git clone git://edryd.org/tisp
Log | Files | Refs | LICENSE

commit 300c5e62ff1f77eddab156462660fdf4f60fb267
parent a74e80895b736f9cd0806cfe4707511829f41a43
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Thu, 27 Jun 2019 15:28:36 -0700

Prevent crash from improper list in print

Diffstat:
tibs/io.c | 18++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/tibs/io.c b/tibs/io.c @@ -23,6 +23,14 @@ #include "../tisp.h" +static void +print_str(Val v) { + if (v->t & STRING) /* don't print quotes around string */ + fprintf(stdout, "%s", v->v.s); + else + tisp_print(stdout, v); +} + static Val prim_print(Env env, Val args) { @@ -30,10 +38,12 @@ prim_print(Env env, Val args) if (!(v = tisp_eval_list(env, args))) return NULL; for (; !nilp(v); v = cdr(v)) { - if (car(v)->t & STRING) /* don't print quotes around string */ - fprintf(stdout, "%s", car(v)->v.s); - else - tisp_print(stdout, car(v)); + if (v->t == PAIR) + print_str(car(v)); + else { + print_str(v); + break; + } } fflush(stdout); return env->none;