ed: Don't clear modflag until is safe

Setting modflag unconditionally in the E command could
produce that after an error happening dealing with the E
command then unsaved files were silently ignored.
This commit is contained in:
Roberto E. Vargas Caballero 2025-12-13 10:42:51 +01:00
parent 9a0d04fcf9
commit 8227fbab2e
2 changed files with 14 additions and 2 deletions

4
ed.c
View File

@ -1448,17 +1448,17 @@ repeat:
chkprint(0);
break;
case 'E':
modflag = 0;
case 'e':
ensureblank();
if (nlines > 0)
goto unexpected;
if (modflag)
if (cmd == 'e' && modflag)
goto modified;
setscratch();
deflines(curln, curln);
doread(getfname(cmd));
clearundo();
modflag = 0;
break;
default:
error("unknown command");

12
tests/0015-ed.sh Executable file
View File

@ -0,0 +1,12 @@
#!/bin/sh
../ed -s /dev/null <<EOF | grep 'file modified' > /dev/null
a
1
2
.
1E
q
h
q
EOF