aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editors/patch.c11
-rwxr-xr-xtestsuite/patch.tests45
2 files changed, 56 insertions, 0 deletions
diff --git a/editors/patch.c b/editors/patch.c
index 4ee9339a7..ea1fc0974 100644
--- a/editors/patch.c
+++ b/editors/patch.c
@@ -290,6 +290,17 @@ static int apply_one_hunk(void)
// out of buffer.
for (;;) {
+ while (plist && *plist->data == "+-"[reverse]) {
+ if (!strcmp(check->data, plist->data+1) &&
+ !backwarn) {
+ backwarn = TT.linenum;
+ if (option_mask32 & FLAG_IGNORE) {
+ dummy_revert = 1;
+ reverse ^= 1;
+ }
+ }
+ plist = plist->next;
+ }
if (!plist || strcmp(check->data, plist->data+1)) {
// Match failed. Write out first line of buffered data and
// recheck remaining buffered data for a new match.
diff --git a/testsuite/patch.tests b/testsuite/patch.tests
index 2759d2ad4..39205242c 100755
--- a/testsuite/patch.tests
+++ b/testsuite/patch.tests
@@ -242,6 +242,51 @@ patch: can't open 'dir2///file': No such file or directory
zxc
"
+testing "patch internal buffering bug?" \
+ 'patch -p1 2>&1; echo $?; cat input' \
+"\
+patching file input
+0
+foo
+
+
+
+
+
+
+1
+2
+3
+
+bar
+" \
+"\
+foo
+
+
+
+
+
+
+
+bar
+" \
+"\
+--- a/input.orig
++++ b/input
+@@ -5,5 +5,8 @@ foo
+
+
+
++1
++2
++3
+
+ bar
+--
+2.9.2
+" \
+
rm input.orig 2>/dev/null
exit $FAILCOUNT