summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-11-05 16:36:03 -0800
committerKaz Kylheku <kaz@kylheku.com>2018-11-05 16:36:03 -0800
commit58d0323c8e957722b99f8c1f998353439dace1a3 (patch)
treeb01134fb5aec2a8c9c7d5c7f98840329216bd5cd
parent8bfe276d821794a5f77ddabdc5187291676bdde4 (diff)
downloadtxr-58d0323c8e957722b99f8c1f998353439dace1a3.tar.gz
txr-58d0323c8e957722b99f8c1f998353439dace1a3.tar.bz2
txr-58d0323c8e957722b99f8c1f998353439dace1a3.zip
bugfix: error on empty script file.
* txr.c (check_hash_bang): When the file is empty, get_line returns nil.
-rw-r--r--txr.c20
1 files 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;
}