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 5364863516ace9b153ba5508c07baacef86127bc
DIR parent daec4db8a3611927158611f3b0cbc082b4673e28
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 Q command could
produce that after an error happening dealing with the Q
command then unsaved files were silently ignored.
Diffstat:
M ed.c | 4 ++--
A tests/0016-ed.sh | 11 +++++++++++
2 files changed, 13 insertions(+), 2 deletions(-)
---
DIR 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':
DIR 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