ed: Don't discard full lines

Discard() was reading stdin until a new line was found, but in
case of having an empty line in the input buffer then it didn't
make sense because we were just discarding the full next line.
This commit is contained in:
Roberto E. Vargas Caballero 2023-09-22 19:43:37 +02:00
parent 2cbf61dff9
commit feeb6e3279
1 changed files with 5 additions and 6 deletions

11
ed.c
View File

@ -76,15 +76,14 @@ discard(void)
{
int c;
if (repidx >= 0)
if (repidx >= 0 || cmdline.siz == 0)
return;
/* discard until the end of the line */
if (cmdline.siz > 0 && cmdline.str[cmdline.siz-1] == '\n')
return;
while ((c = getchar()) != '\n' && c != EOF)
;
if (cmdline.str[cmdline.siz-1] != '\n') {
while ((c = getchar()) != '\n' && c != EOF)
;
}
}
static void undo(void);