diff options
author | Rob Landley <rob@landley.net> | 2010-08-13 16:40:21 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-08-13 16:40:21 +0200 |
commit | 760d0ebbe5edaedb60b4de64bde2ad098d1f45d9 (patch) | |
tree | 400a88cc5c7588a5dbb574f84f750fa308bf6f37 | |
parent | 1bbc0cd7f293aac5e15d6c1e16bee9f1484c6fbf (diff) | |
download | busybox-w32-760d0ebbe5edaedb60b4de64bde2ad098d1f45d9.tar.gz busybox-w32-760d0ebbe5edaedb60b4de64bde2ad098d1f45d9.tar.bz2 busybox-w32-760d0ebbe5edaedb60b4de64bde2ad098d1f45d9.zip |
patch: deal with ommitted ",len" in hunk headers (default len to 1)
Signed-off-by: Rob Landley <rob@landley.net>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/patch.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/editors/patch.c b/editors/patch.c index 7f3234e66..b12c662f4 100644 --- a/editors/patch.c +++ b/editors/patch.c | |||
@@ -227,7 +227,8 @@ struct globals { | |||
227 | long prefix; | 227 | long prefix; |
228 | 228 | ||
229 | struct double_list *current_hunk; | 229 | struct double_list *current_hunk; |
230 | long oldline, oldlen, newline, newlen, linenum; | 230 | long oldline, oldlen, newline, newlen; |
231 | long linenum; | ||
231 | int context, state, filein, fileout, filepatch, hunknum; | 232 | int context, state, filein, fileout, filepatch, hunknum; |
232 | char *tempname; | 233 | char *tempname; |
233 | 234 | ||
@@ -505,14 +506,19 @@ int patch_main(int argc UNUSED_PARAM, char **argv) | |||
505 | // way the patch man page says, so you have to read the first hunk | 506 | // way the patch man page says, so you have to read the first hunk |
506 | // and _guess_. | 507 | // and _guess_. |
507 | 508 | ||
508 | // Start a new hunk? | 509 | // Start a new hunk? Usually @@ -oldline,oldlen +newline,newlen @@ |
510 | // but a missing ,value means the value is 1. | ||
509 | } else if (state == 1 && !strncmp("@@ -", patchline, 4)) { | 511 | } else if (state == 1 && !strncmp("@@ -", patchline, 4)) { |
510 | int i; | 512 | int i; |
513 | char *s = patchline+4; | ||
511 | 514 | ||
512 | i = sscanf(patchline+4, "%ld,%ld +%ld,%ld", &TT.oldline, | 515 | // Read oldline[,oldlen] +newline[,newlen] |
513 | &TT.oldlen, &TT.newline, &TT.newlen); | 516 | |
514 | if (i != 4) | 517 | TT.oldlen = TT.newlen = 1; |
515 | bb_error_msg_and_die("corrupt hunk %d at %ld", TT.hunknum, TT.linenum); | 518 | TT.oldline = strtol(s, &s, 10); |
519 | if (*s == ',') TT.oldlen=strtol(s+1, &s, 10); | ||
520 | TT.newline = strtol(s+2, &s, 10); | ||
521 | if (*s == ',') TT.newlen = strtol(s+1, &s, 10); | ||
516 | 522 | ||
517 | TT.context = 0; | 523 | TT.context = 0; |
518 | state = 2; | 524 | state = 2; |
@@ -520,7 +526,7 @@ int patch_main(int argc UNUSED_PARAM, char **argv) | |||
520 | // If this is the first hunk, open the file. | 526 | // If this is the first hunk, open the file. |
521 | if (TT.filein == -1) { | 527 | if (TT.filein == -1) { |
522 | int oldsum, newsum, del = 0; | 528 | int oldsum, newsum, del = 0; |
523 | char *s, *name; | 529 | char *name; |
524 | 530 | ||
525 | oldsum = TT.oldline + TT.oldlen; | 531 | oldsum = TT.oldline + TT.oldlen; |
526 | newsum = TT.newline + TT.newlen; | 532 | newsum = TT.newline + TT.newlen; |