From 8227fbab2e1209bf68125e19d366ffacdc2071d2 Mon Sep 17 00:00:00 2001 From: "Roberto E. Vargas Caballero" Date: Sat, 13 Dec 2025 10:42:51 +0100 Subject: [PATCH] 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. --- ed.c | 4 ++-- tests/0015-ed.sh | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100755 tests/0015-ed.sh diff --git a/ed.c b/ed.c index c994956..1016f21 100644 --- 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 new file mode 100755 index 0000000..9dfea4a --- /dev/null +++ b/tests/0015-ed.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +../ed -s /dev/null < /dev/null +a +1 +2 +. +1E +q +h +q +EOF