commit 5364863516ace9b153ba5508c07baacef86127bc
parent daec4db8a3611927158611f3b0cbc082b4673e28
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 Q command could
produce that after an error happening dealing with the Q
command then unsaved files were silently ignored.
Diffstat:
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/ed.c b/ed.c
@@ -1429,12 +1429,12 @@ repeat:
optprompt ^= 1;
break;
case 'Q':
- modflag = 0;
case 'q':
if (nlines > 0)
goto unexpected;
- if (modflag)
+ if (cmd != 'Q' && modflag)
goto modified;
+ modflag = 0;
quit();
break;
case 'f':
diff --git a/tests/0016-ed.sh b/tests/0016-ed.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+../ed -s /dev/null <<EOF | grep 'file modified' > /dev/null
+a
+1
+2
+.
+1Q
+q
+h
+EOF