commit 8227fbab2e1209bf68125e19d366ffacdc2071d2
parent 9a0d04fcf9ac486a4056a3641ecb098a227166af
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Sat, 13 Dec 2025 10:42:51 +0100
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.
Diffstat:
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/ed.c b/ed.c
@@ -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");
diff --git a/tests/0015-ed.sh b/tests/0015-ed.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+../ed -s /dev/null <<EOF | grep 'file modified' > /dev/null
+a
+1
+2
+.
+1E
+q
+h
+q
+EOF