summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortobias <tobias>2016-02-22 19:31:38 +0000
committertobias <tobias>2016-02-22 19:31:38 +0000
commit63c366dc875d2090bee7f3bd1133def63bf26593 (patch)
tree79eeeba665598d84a57e8218409aa224a9bf1872
parentf4c1780549b57a85dbefdd61bf3c65f1a51f97e3 (diff)
downloadpatch-63c366dc875d2090bee7f3bd1133def63bf26593.tar
patch-63c366dc875d2090bee7f3bd1133def63bf26593.tar.gz
Properly handle ed-files which fully replace input file content. ThisOPENBSD_5_9_BASE
misbehaviour is triggered with 'c' and 'i' commands on empty buffers. Spotted and fixed by Martin Natano <natano at natano dot net>. ok millert@
-rw-r--r--ed.c27
1 files changed, 10 insertions, 17 deletions
diff --git a/ed.c b/ed.c
index a8ea15d..c5f4666 100644
--- a/ed.c
+++ b/ed.c
@@ -121,23 +121,16 @@ do_ed_script(void)
continue;
}
- if (fsm == FSM_A) {
- nline = create_line(linepos);
- if (cline == NULL)
- LIST_INSERT_HEAD(&head, nline, entries);
- else
- LIST_INSERT_AFTER(cline, nline, entries);
- cline = nline;
- line_count++;
- } else if (fsm == FSM_I) {
- nline = create_line(linepos);
- if (cline == NULL) {
- LIST_INSERT_HEAD(&head, nline, entries);
- cline = nline;
- } else
- LIST_INSERT_BEFORE(cline, nline, entries);
- line_count++;
- }
+ nline = create_line(linepos);
+ if (cline == NULL)
+ LIST_INSERT_HEAD(&head, nline, entries);
+ else if (fsm == FSM_A)
+ LIST_INSERT_AFTER(cline, nline, entries);
+ else
+ LIST_INSERT_BEFORE(cline, nline, entries);
+ cline = nline;
+ line_count++;
+ fsm = FSM_A;
}
next_intuit_at(linepos, p_input_line);