From c9f494a3dfba6b2edd2bab2d2f9e569eb8fba9e6 Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Wed, 22 Jul 2015 01:20:34 +0200 Subject: [PATCH] EOF on the prompt should not loop infinitely --- src/klh10.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/klh10.c b/src/klh10.c index 4b68f3f..09e4d4a 100644 --- a/src/klh10.c +++ b/src/klh10.c @@ -1032,8 +1032,15 @@ cmdlsetup(struct cmd_s *cm) fputs(cp, stdout); /* Echo the input line */ } else { cp = fe_ctycmline(cm->cmd_inp, (int)cm->cmd_left-1); - if (cp == NULL) - return NULL; + if (cp == NULL) { + if (feof(stdin) || ferror(stdin)) { + cp = strncpy(cm->cmd_inp, "exit", (int)cm->cmd_left-1); + fprintf(stdout, "exit\n"); + clearerr(stdin); + } else { + return NULL; + } + } } len = strlen(cp);