diff options
Diffstat (limited to 'editors/patch.c')
-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; |