diff options
author | Aaro Koskinen <aaro.koskinen@iki.fi> | 2016-11-22 00:19:51 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2016-11-24 11:40:36 +0100 |
commit | cb810c48c036f50c19b08df7e161cdb0550a2abd (patch) | |
tree | fe18bf724cb5c53ae9861e778bbf6db1bce712f6 | |
parent | 2eff59667d3c590f27ee39cd0969b2221af739a0 (diff) | |
download | busybox-w32-cb810c48c036f50c19b08df7e161cdb0550a2abd.tar.gz busybox-w32-cb810c48c036f50c19b08df7e161cdb0550a2abd.tar.bz2 busybox-w32-cb810c48c036f50c19b08df7e161cdb0550a2abd.zip |
patch: fix matching failure
Fix matching failure when plist is advanced while checking for buffered
lines - the lines in the hunk that are about to be added should be
skipped when checking for matching context.
Also add a valid test case that fails with current busybox and is fixed
by the change.
Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/patch.c | 11 | ||||
-rwxr-xr-x | testsuite/patch.tests | 45 |
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) | |||
290 | // out of buffer. | 290 | // out of buffer. |
291 | 291 | ||
292 | for (;;) { | 292 | for (;;) { |
293 | while (plist && *plist->data == "+-"[reverse]) { | ||
294 | if (!strcmp(check->data, plist->data+1) && | ||
295 | !backwarn) { | ||
296 | backwarn = TT.linenum; | ||
297 | if (option_mask32 & FLAG_IGNORE) { | ||
298 | dummy_revert = 1; | ||
299 | reverse ^= 1; | ||
300 | } | ||
301 | } | ||
302 | plist = plist->next; | ||
303 | } | ||
293 | if (!plist || strcmp(check->data, plist->data+1)) { | 304 | if (!plist || strcmp(check->data, plist->data+1)) { |
294 | // Match failed. Write out first line of buffered data and | 305 | // Match failed. Write out first line of buffered data and |
295 | // recheck remaining buffered data for a new match. | 306 | // 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 | |||
242 | zxc | 242 | zxc |
243 | " | 243 | " |
244 | 244 | ||
245 | testing "patch internal buffering bug?" \ | ||
246 | 'patch -p1 2>&1; echo $?; cat input' \ | ||
247 | "\ | ||
248 | patching file input | ||
249 | 0 | ||
250 | foo | ||
251 | |||
252 | |||
253 | |||
254 | |||
255 | |||
256 | |||
257 | 1 | ||
258 | 2 | ||
259 | 3 | ||
260 | |||
261 | bar | ||
262 | " \ | ||
263 | "\ | ||
264 | foo | ||
265 | |||
266 | |||
267 | |||
268 | |||
269 | |||
270 | |||
271 | |||
272 | bar | ||
273 | " \ | ||
274 | "\ | ||
275 | --- a/input.orig | ||
276 | +++ b/input | ||
277 | @@ -5,5 +5,8 @@ foo | ||
278 | |||
279 | |||
280 | |||
281 | +1 | ||
282 | +2 | ||
283 | +3 | ||
284 | |||
285 | bar | ||
286 | -- | ||
287 | 2.9.2 | ||
288 | " \ | ||
289 | |||
245 | rm input.orig 2>/dev/null | 290 | rm input.orig 2>/dev/null |
246 | 291 | ||
247 | exit $FAILCOUNT | 292 | exit $FAILCOUNT |