aboutsummaryrefslogtreecommitdiff
path: root/editors/patch.c
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/patch.c
parent0ab45da92990072a23fda0f35d068743b1067cf3 (diff)
downloadbusybox-8027a202a89b31b33c94eae29895f14ceceef5af.tar.gz
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/patch.c')
-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)
// complete hunk.
plist = TT.current_hunk;
buf = NULL;
- if (TT.context) for (;;) {
+ if (reverse ? TT.oldlen : TT.newlen) for (;;) {
char *data = xmalloc_reads(TT.filein, NULL, NULL);
TT.linenum++;
@@ -352,6 +352,8 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
int reverse, state = 0;
char *oldname = NULL, *newname = NULL;
char *opt_p, *opt_i;
+ long oldlen = oldlen; /* for compiler */
+ long newlen = newlen; /* for compiler */
INIT_TT();
@@ -391,8 +393,8 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
if (*patchline==' ' || *patchline=='+' || *patchline=='-') {
dlist_add(&TT.current_hunk, patchline);
- if (*patchline != '+') TT.oldlen--;
- if (*patchline != '-') TT.newlen--;
+ if (*patchline != '+') oldlen--;
+ if (*patchline != '-') newlen--;
// Context line?
if (*patchline==' ' && state==2) TT.context++;
@@ -400,7 +402,7 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
// If we've consumed all expected hunk lines, apply the hunk.
- if (!TT.oldlen && !TT.newlen) state = apply_one_hunk();
+ if (!oldlen && !newlen) state = apply_one_hunk();
continue;
}
fail_hunk();
@@ -447,11 +449,14 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
// Read oldline[,oldlen] +newline[,newlen]
- TT.oldlen = TT.newlen = 1;
+ TT.oldlen = oldlen = TT.newlen = newlen = 1;
TT.oldline = strtol(s, &s, 10);
- if (*s == ',') TT.oldlen=strtol(s+1, &s, 10);
+ if (*s == ',') TT.oldlen = oldlen = strtol(s+1, &s, 10);
TT.newline = strtol(s+2, &s, 10);
- if (*s == ',') TT.newlen = strtol(s+1, &s, 10);
+ if (*s == ',') TT.newlen = newlen = strtol(s+1, &s, 10);
+
+ if (oldlen < 1 && newlen < 1)
+ bb_error_msg_and_die("Really? %s", patchline);
TT.context = 0;
state = 2;
@@ -461,8 +466,8 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
int oldsum, newsum, empty = 0;
char *name;
- oldsum = TT.oldline + TT.oldlen;
- newsum = TT.newline + TT.newlen;
+ oldsum = TT.oldline + oldlen;
+ newsum = TT.newline + newlen;
name = reverse ? oldname : newname;