fpjohnston / TECO-64

Enhanced and portable version of TECO text editor in C.
24 stars 6 forks source link

`^N` (end of file flag) cause crashes when no input file. #27

Open LdBeth opened 2 months ago

LdBeth commented 2 months ago

And a fix is provided:

diff --git a/src/flag_cmd.c b/src/flag_cmd.c
index e73646a2..9ede57df 100644
--- a/src/flag_cmd.c
+++ b/src/flag_cmd.c
@@ -514,9 +514,13 @@ bool scan_flag1(struct cmd *cmd)
             confirm(cmd, NO_N);

             struct ifile *ifile = &ifiles[istream];
-            int_t eof = feof(ifile->fp) ? -1 : 0;
+            if (ifile->fp == NULL)
+              store_val(0);
+            else {
+              int_t eof = feof(ifile->fp) ? -1 : 0;

-            store_val(eof);
+              store_val(eof);
+            }

             return true;
         }