diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2018-11-05 16:36:03 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2018-11-05 16:36:03 -0800 |
commit | 58d0323c8e957722b99f8c1f998353439dace1a3 (patch) | |
tree | b01134fb5aec2a8c9c7d5c7f98840329216bd5cd | |
parent | 8bfe276d821794a5f77ddabdc5187291676bdde4 (diff) | |
download | txr-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.c | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -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; } |