sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

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:
Med.c | 4++--
Atests/0016-ed.sh | 11+++++++++++
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