[hackers] [sbase] ed: Don't clear modflag until is safe || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Sat, 13 Dec 2025 10:44:11 +0100 (CET)

commit 8227fbab2e1209bf68125e19d366ffacdc2071d2
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.net>
AuthorDate: Sat Dec 13 10:42:51 2025 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.net>
CommitDate: Sat Dec 13 10:42:51 2025 +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.

diff --git a/ed.c b/ed.c
index c994956..1016f21 100644
--- a/ed.c
+++ b/ed.c
_AT_@ -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
new file mode 100755
index 0000000..9dfea4a
--- /dev/null
+++ b/tests/0015-ed.sh
_AT_@ -0,0 +1,12 @@
+#!/bin/sh
+
+../ed -s /dev/null <<EOF | grep 'file modified' > /dev/null
+a
+1
+2
+.
+1E
+q
+h
+q
+EOF
Received on Sat Dec 13 2025 - 10:44:11 CET

This archive was generated by hypermail 2.3.0 : Sat Dec 13 2025 - 10:48:34 CET