aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/patch.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-08-05 19:27:02 -0500
committerRob Landley <rob@landley.net>2014-08-05 19:27:02 -0500
commit9fdc1fe5033cbc8922e4bb65900b3696b7ae938d (patch)
treee693db7a493fe4c0460275f330ab976cb01bcd16 /toys/posix/patch.c
parent4edcd084f4782518249b888efc5d8f965bd5742e (diff)
downloadtoybox-9fdc1fe5033cbc8922e4bb65900b3696b7ae938d.tar.gz
Fix a couple patch bugs concerning error output.
Diffstat (limited to 'toys/posix/patch.c')
-rw-r--r--toys/posix/patch.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/toys/posix/patch.c b/toys/posix/patch.c
index 45dce1f6..e02bfa93 100644
--- a/toys/posix/patch.c
+++ b/toys/posix/patch.c
@@ -93,7 +93,6 @@ static void finish_oldfile(void)
static void fail_hunk(void)
{
if (!TT.current_hunk) return;
- dlist_terminate(TT.current_hunk);
fprintf(stderr, "Hunk %d FAILED %ld/%ld.\n",
TT.hunknum, TT.oldline, TT.newline);
@@ -137,7 +136,6 @@ static int apply_one_hunk(void)
int (*lcmp)(char *aa, char *bb);
lcmp = (toys.optflags & FLAG_l) ? (void *)loosecmp : (void *)strcmp;
-
dlist_terminate(TT.current_hunk);
// Match EOF if there aren't as many ending context lines as beginning
@@ -203,9 +201,12 @@ static int apply_one_hunk(void)
if (PATCH_DEBUG) {
int bug = 0;
- while (plist->data[bug] == check->data[bug]) bug++;
- fprintf(stderr, "NOT(%d:%d!=%d): %s\n", bug, plist->data[bug],
- check->data[bug], plist->data);
+ if (!plist) fprintf(stderr, "NULL plist\n");
+ else {
+ while (plist->data[bug] == check->data[bug]) bug++;
+ fprintf(stderr, "NOT(%d:%d!=%d): %s\n", bug, plist->data[bug],
+ check->data[bug], plist->data);
+ }
}
TT.state = 3;
@@ -297,6 +298,7 @@ void patch_main(void)
if (!TT.oldlen && !TT.newlen) state = apply_one_hunk();
continue;
}
+ dlist_terminate(TT.current_hunk);
fail_hunk();
state = 0;
continue;