aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2010-11-29 03:24:51 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2010-11-29 03:24:51 +0100
commit8027a202a89b31b33c94eae29895f14ceceef5af (patch)
treed4e996a42e5d059df338a2250fca1b477fa39dd3 /editors
parent0ab45da92990072a23fda0f35d068743b1067cf3 (diff)
downloadbusybox-w32-8027a202a89b31b33c94eae29895f14ceceef5af.tar.gz
busybox-w32-8027a202a89b31b33c94eae29895f14ceceef5af.tar.bz2
busybox-w32-8027a202a89b31b33c94eae29895f14ceceef5af.zip
patch: fix "patch at the beginning" testcase failure
Signed-off-by: Rob Landley <rob@landley.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors')
-rw-r--r--editors/patch.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/editors/patch.c b/editors/patch.c
index 1d4a2554e..9c6d967b9 100644
--- a/editors/patch.c
+++ b/editors/patch.c
@@ -238,7 +238,7 @@ static int apply_one_hunk(void)
238 // complete hunk. 238 // complete hunk.
239 plist = TT.current_hunk; 239 plist = TT.current_hunk;
240 buf = NULL; 240 buf = NULL;
241 if (TT.context) for (;;) { 241 if (reverse ? TT.oldlen : TT.newlen) for (;;) {
242 char *data = xmalloc_reads(TT.filein, NULL, NULL); 242 char *data = xmalloc_reads(TT.filein, NULL, NULL);
243 243
244 TT.linenum++; 244 TT.linenum++;
@@ -352,6 +352,8 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
352 int reverse, state = 0; 352 int reverse, state = 0;
353 char *oldname = NULL, *newname = NULL; 353 char *oldname = NULL, *newname = NULL;
354 char *opt_p, *opt_i; 354 char *opt_p, *opt_i;
355 long oldlen = oldlen; /* for compiler */
356 long newlen = newlen; /* for compiler */
355 357
356 INIT_TT(); 358 INIT_TT();
357 359
@@ -391,8 +393,8 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
391 if (*patchline==' ' || *patchline=='+' || *patchline=='-') { 393 if (*patchline==' ' || *patchline=='+' || *patchline=='-') {
392 dlist_add(&TT.current_hunk, patchline); 394 dlist_add(&TT.current_hunk, patchline);
393 395
394 if (*patchline != '+') TT.oldlen--; 396 if (*patchline != '+') oldlen--;
395 if (*patchline != '-') TT.newlen--; 397 if (*patchline != '-') newlen--;
396 398
397 // Context line? 399 // Context line?
398 if (*patchline==' ' && state==2) TT.context++; 400 if (*patchline==' ' && state==2) TT.context++;
@@ -400,7 +402,7 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
400 402
401 // If we've consumed all expected hunk lines, apply the hunk. 403 // If we've consumed all expected hunk lines, apply the hunk.
402 404
403 if (!TT.oldlen && !TT.newlen) state = apply_one_hunk(); 405 if (!oldlen && !newlen) state = apply_one_hunk();
404 continue; 406 continue;
405 } 407 }
406 fail_hunk(); 408 fail_hunk();
@@ -447,11 +449,14 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
447 449
448 // Read oldline[,oldlen] +newline[,newlen] 450 // Read oldline[,oldlen] +newline[,newlen]
449 451
450 TT.oldlen = TT.newlen = 1; 452 TT.oldlen = oldlen = TT.newlen = newlen = 1;
451 TT.oldline = strtol(s, &s, 10); 453 TT.oldline = strtol(s, &s, 10);
452 if (*s == ',') TT.oldlen=strtol(s+1, &s, 10); 454 if (*s == ',') TT.oldlen = oldlen = strtol(s+1, &s, 10);
453 TT.newline = strtol(s+2, &s, 10); 455 TT.newline = strtol(s+2, &s, 10);
454 if (*s == ',') TT.newlen = strtol(s+1, &s, 10); 456 if (*s == ',') TT.newlen = newlen = strtol(s+1, &s, 10);
457
458 if (oldlen < 1 && newlen < 1)
459 bb_error_msg_and_die("Really? %s", patchline);
455 460
456 TT.context = 0; 461 TT.context = 0;
457 state = 2; 462 state = 2;
@@ -461,8 +466,8 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
461 int oldsum, newsum, empty = 0; 466 int oldsum, newsum, empty = 0;
462 char *name; 467 char *name;
463 468
464 oldsum = TT.oldline + TT.oldlen; 469 oldsum = TT.oldline + oldlen;
465 newsum = TT.newline + TT.newlen; 470 newsum = TT.newline + newlen;
466 471
467 name = reverse ? oldname : newname; 472 name = reverse ? oldname : newname;
468 473