From 3b44f0bb9381c437b4e94c29d00022a9ff44022c Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 5 Nov 2018 16:36:03 -0800 Subject: bugfix: error on empty script file. * txr.c (check_hash_bang): When the file is empty, get_line returns nil. --- txr.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/txr.c b/txr.c index 9dda1cc6..56ff6bf8 100644 --- a/txr.c +++ b/txr.c @@ -192,17 +192,21 @@ static void hint(void) static val check_hash_bang(val stream, val args) { val line = get_line(stream); - if (match_str(line, lit("#!"), nil)) { - val pos = search_str(line, lit("\xdc00"), nil, nil); - if (pos) { - val after_null = sub_str(line, succ(pos), t); - val prepend_args = split_str(after_null, lit(" ")); - args = nappend2(prepend_args, args); + if (line) { + if (match_str(line, lit("#!"), nil)) { + val pos = search_str(line, lit("\xdc00"), nil, nil); + + if (pos) { + val after_null = sub_str(line, succ(pos), t); + val prepend_args = split_str(after_null, lit(" ")); + args = nappend2(prepend_args, args); + } + } else { + seek_stream(stream, zero, from_start_k); } - } else { - seek_stream(stream, zero, from_start_k); } + return args; } -- cgit v1.2.3