diff options
author | 2016-02-22 19:31:38 +0000 | |
---|---|---|
committer | 2016-02-22 19:31:38 +0000 | |
commit | 4125338f3ff66e311a5b187bbe032fce12444df7 (patch) | |
tree | 474e74f57a6e5b60887dbee5601fb7bb8f9485e4 /usr.bin/patch/ed.c | |
parent | the default address family for a listener was set too late and would (diff) | |
download | wireguard-openbsd-4125338f3ff66e311a5b187bbe032fce12444df7.tar.xz wireguard-openbsd-4125338f3ff66e311a5b187bbe032fce12444df7.zip |
Properly handle ed-files which fully replace input file content. This
misbehaviour is triggered with 'c' and 'i' commands on empty buffers.
Spotted and fixed by Martin Natano <natano at natano dot net>.
ok millert@
Diffstat (limited to 'usr.bin/patch/ed.c')
-rw-r--r-- | usr.bin/patch/ed.c | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/usr.bin/patch/ed.c b/usr.bin/patch/ed.c index 0196ff61369..baac4e5decd 100644 --- a/usr.bin/patch/ed.c +++ b/usr.bin/patch/ed.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ed.c,v 1.1 2015/10/16 07:33:47 tobias Exp $ */ +/* $OpenBSD: ed.c,v 1.2 2016/02/22 19:31:38 tobias Exp $ */ /* * Copyright (c) 2015 Tobias Stoeckmann <tobias@openbsd.org> @@ -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); |