# HG changeset patch # User Rob Landley # Date 1407284822 18000 # Node ID 88aaf45c7fbba66f1c6e86697e3526b97d20422d # Parent 30014454681f3a58ab8dd907a0e3033ff4201753 Fix a couple patch bugs concerning error output. diff -r 30014454681f -r 88aaf45c7fbb toys/posix/patch.c --- a/toys/posix/patch.c Mon Aug 04 19:28:41 2014 -0500 +++ b/toys/posix/patch.c Tue Aug 05 19:27:02 2014 -0500 @@ -93,7 +93,6 @@ 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 @@ 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 @@ 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 @@ if (!TT.oldlen && !TT.newlen) state = apply_one_hunk(); continue; } + dlist_terminate(TT.current_hunk); fail_hunk(); state = 0; continue;