From 4d5a1cc076a071074339912e0245195c8f1321f5 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Wed, 10 Aug 2016 19:01:32 -0400 Subject: [PATCH] Issue #90 - Typecheck port argument --- runtime.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/runtime.c b/runtime.c index bdc7d0c8..606980b4 100644 --- a/runtime.c +++ b/runtime.c @@ -645,7 +645,13 @@ object Cyc_display_va_list(int argc, object x, va_list ap) if (argc > 1) { object tmp; tmp = va_arg(ap, object); - fp = ((port_type *) tmp)->fp; + if (Cyc_is_port(tmp) == boolean_t) { + fp = ((port_type *) tmp)->fp; + } else { + // TODO: need a data arg, and should raise an error here instead + fprintf(stderr, "Bad argument: expected port\n"); + exit(1); + } } return Cyc_display(x, fp); } @@ -802,7 +808,13 @@ object Cyc_write_va_list(int argc, object x, va_list ap) if (argc > 1) { object tmp; tmp = va_arg(ap, object); - fp = ((port_type *) tmp)->fp; + if (Cyc_is_port(tmp) == boolean_t) { + fp = ((port_type *) tmp)->fp; + } else { + // TODO: need a data arg, and should raise an error here instead + fprintf(stderr, "Bad argument: expected port\n"); + exit(1); + } } return Cyc_write(x, fp); }