Bug 226218 - "r"eading into an empty ed(1) buffer doesn't set modified status
Summary: "r"eading into an empty ed(1) buffer doesn't set modified status
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2018-02-26 13:49 UTC by Tim Chase
Modified: 2018-02-27 15:28 UTC (History)
1 user (show)

See Also:


Attachments
Remove the broken check for "addr != addr_last" in /usr/src/bin/ed/main.c (315 bytes, patch)
2018-02-26 13:49 UTC, Tim Chase
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.