Bug 226218

Summary: "r"eading into an empty ed(1) buffer doesn't set modified status
Product: Base System Reporter: Tim Chase <freebsd>
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: New ---    
Severity: Affects Some People CC: freebsd
Priority: --- Keywords: patch
Version: CURRENT   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
Remove the broken check for "addr != addr_last" in /usr/src/bin/ed/main.c none

Description Tim Chase 2018-02-26 13:49:03 UTC
Created attachment 191017 [details]
Remove the broken check for "addr != addr_last" in /usr/src/bin/ed/main.c

To reproduce:

 $ ed
 r file.txt
 314
 q
 $

Expected behavior:

 $ ed
 r file.txt
 314
 q
 ?
 q
 $

which keeps it in line with the POSIX requirement

http://pubs.opengroup.org/onlinepubs/009604599/utilities/ed.html

"If the buffer has changed since the last time the entire buffer was written, the user shall be warned"

Reading a file changes the buffer. Compare with the correct

 $ ed
 a
 x
 .
 q
 ?
 q
 $

where the buffer is changed and the "modified" flag is properly set.

The solution appears to be to base "modified" purely on whether any lines were read in (addr > 0), regardless of whether "addr != addr_last" as performed by the attached patch.