diff options
author | Tobias Stoeckmann <tobias@cvs.openbsd.org> | 2016-02-22 19:31:39 +0000 |
---|---|---|
committer | Tobias Stoeckmann <tobias@cvs.openbsd.org> | 2016-02-22 19:31:39 +0000 |
commit | 49011cab98d485eb981076c871c0a6ca0daf4a84 (patch) | |
tree | 379001f1c672358818c9225b269f617b1ea51d64 | |
parent | ceedca6f43776a7ce90db20acb1e65bc6855033c (diff) |
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@
-rw-r--r-- | regress/usr.bin/patch/Makefile | 7 | ||||
-rw-r--r-- | regress/usr.bin/patch/t18.diff | 10 | ||||
-rw-r--r-- | regress/usr.bin/patch/t18.in | 3 | ||||
-rw-r--r-- | regress/usr.bin/patch/t18.out | 5 | ||||
-rw-r--r-- | usr.bin/patch/ed.c | 29 |
5 files changed, 33 insertions, 21 deletions
diff --git a/regress/usr.bin/patch/Makefile b/regress/usr.bin/patch/Makefile index bfe2b8013d8..28a8e28048a 100644 --- a/regress/usr.bin/patch/Makefile +++ b/regress/usr.bin/patch/Makefile @@ -1,9 +1,9 @@ -# $OpenBSD: Makefile,v 1.9 2015/10/13 17:07:05 tobias Exp $ +# $OpenBSD: Makefile,v 1.10 2016/02/22 19:31:38 tobias Exp $ PATCH=patch PATCHOPTIONS=-sN -REGRESS_TARGETS=t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 +REGRESS_TARGETS=t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 t18 # .in: input file # .diff: patch @@ -23,7 +23,8 @@ REGRESS_TARGETS=t1 t2 t3 t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 # t14: diff in normal diff format. # t15: diff in context diff format. # t16: diff in ed format. -# t17: diff in ed format that inserts a dot-line +# t17: diff in ed format that inserts a dot-line. +# t18: diff in ed format that fully replaces input content. all: clean ${REGRESS_TARGET} diff --git a/regress/usr.bin/patch/t18.diff b/regress/usr.bin/patch/t18.diff new file mode 100644 index 00000000000..840b707ac53 --- /dev/null +++ b/regress/usr.bin/patch/t18.diff @@ -0,0 +1,10 @@ +1,3c +W +X +.. +. +3s/.// +3a +Y +Z +. diff --git a/regress/usr.bin/patch/t18.in b/regress/usr.bin/patch/t18.in new file mode 100644 index 00000000000..b1e67221afe --- /dev/null +++ b/regress/usr.bin/patch/t18.in @@ -0,0 +1,3 @@ +A +B +C diff --git a/regress/usr.bin/patch/t18.out b/regress/usr.bin/patch/t18.out new file mode 100644 index 00000000000..33921bb2ebd --- /dev/null +++ b/regress/usr.bin/patch/t18.out @@ -0,0 +1,5 @@ +W +X +. +Y +Z 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); |