URI: 
       ed: Don't clear modflag until is safe - sbase - suckless unix tools
  HTML git clone git://git.suckless.org/sbase
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 8227fbab2e1209bf68125e19d366ffacdc2071d2
   DIR parent 9a0d04fcf9ac486a4056a3641ecb098a227166af
  HTML 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:
         M ed.c                                |       4 ++--
         A tests/0015-ed.sh                    |      12 ++++++++++++
       
       2 files changed, 14 insertions(+), 2 deletions(-)
       ---
   DIR 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");
   DIR 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