From b5df2a25a2bf2129e3a26dffcf66b77d1d1cc3a8 Mon Sep 17 00:00:00 2001 From: Michael Mikonos <127171689+mknos@users.noreply.github.com> Date: Mon, 27 Jan 2025 17:32:27 +0800 Subject: [PATCH] ed: buffer is dirty unless all lines were written (#932) * I found a case where ed allowed unsaved changes to be lost * The default behaviour of "w" command is to write all lines from the editor buffer * In the case of 1w or 1,2w command, only the selected lines are written and there may be unsaved changes on other lines, so don't unset the "dirty" flag * The flag should be unmodified also in the case of "w !cat", where all buffer lines are written to a pipe * This patch makes ed consistent with BSD and GNU versions --- bin/ed | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bin/ed b/bin/ed index 0adfc0be..cecbf126 100755 --- a/bin/ed +++ b/bin/ed @@ -679,8 +679,12 @@ sub edWrite { warn "$filename: $!\n"; return E_CLOSE; } - - $NeedToSave = $UserHasBeenWarned = 0; + unless ($do_pipe) { + my $lcount = $adrs[1] - $adrs[0] + 1; + if ($lcount == maxline()) { + $NeedToSave = $UserHasBeenWarned = 0; + } + } print "$chars\n" unless $Scripted; exit getrc() if $qflag; return;