=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/patch/pch.c,v retrieving revision 1.27 retrieving revision 1.28 diff -c -r1.27 -r1.28 *** src/usr.bin/patch/pch.c 2003/07/29 20:10:17 1.27 --- src/usr.bin/patch/pch.c 2003/08/01 20:30:48 1.28 *************** *** 1,13 **** ! /* $OpenBSD: pch.c,v 1.27 2003/07/29 20:10:17 millert Exp $ */ #ifndef lint ! static const char rcsid[] = "$OpenBSD: pch.c,v 1.27 2003/07/29 20:10:17 millert Exp $"; #endif /* not lint */ #include #include - #include #include #include #include --- 1,12 ---- ! /* $OpenBSD: pch.c,v 1.28 2003/08/01 20:30:48 otto Exp $ */ #ifndef lint ! static const char rcsid[] = "$OpenBSD: pch.c,v 1.28 2003/08/01 20:30:48 otto Exp $"; #endif /* not lint */ #include #include #include #include #include *************** *** 115,126 **** { hunkmax *= 2; ! /* ! * Note that on most systems, only the p_line array ever gets fresh memory ! * since p_len can move into p_line's old space, and p_char can move into ! * p_len's old space. Not on PDP-11's however. But it doesn't matter. ! */ ! assert(p_line != NULL && p_len != NULL && p_char != NULL); p_line = realloc(p_line, hunkmax * sizeof(char *)); p_len = realloc(p_len, hunkmax * sizeof(short)); --- 114,121 ---- { hunkmax *= 2; ! if (p_line == NULL || p_len == NULL || p_char == NULL) ! fatal("Internal memory allocation error\n"); p_line = realloc(p_line, hunkmax * sizeof(char *)); p_len = realloc(p_len, hunkmax * sizeof(short)); *************** *** 130,137 **** return; if (!using_plan_a) fatal("out of memory\n"); ! out_of_mem = TRUE; /* whatever is null will be allocated again */ ! /* from within plan_a(), of all places */ } /* True if the remainder of the patch file contains a diff of some sort. */ --- 125,132 ---- return; if (!using_plan_a) fatal("out of memory\n"); ! out_of_mem = true; /* whatever is null will be allocated again */ ! /* from within plan_a(), of all places */ } /* True if the remainder of the patch file contains a diff of some sort. */ *************** *** 142,148 **** if (p_base != 0L && p_base >= p_filesize) { if (verbose) say("done\n"); ! return FALSE; } if (verbose) say("Hmm..."); --- 137,143 ---- if (p_base != 0L && p_base >= p_filesize) { if (verbose) say("done\n"); ! return false; } if (verbose) say("Hmm..."); *************** *** 153,159 **** say(" Ignoring the trailing garbage.\ndone\n"); } else say(" I can't seem to find a patch in there anywhere.\n"); ! return FALSE; } if (verbose) say(" %sooks like %s to me...\n", --- 148,154 ---- say(" Ignoring the trailing garbage.\ndone\n"); } else say(" I can't seem to find a patch in there anywhere.\n"); ! return false; } if (verbose) say(" %sooks like %s to me...\n", *************** *** 171,184 **** if (force || batch) { say("No file to patch. Skipping...\n"); filearg[0] = savestr(bestguess); ! skip_rest_of_patch = TRUE; ! return TRUE; } ask("File to patch: "); if (*buf != '\n') { free(bestguess); bestguess = savestr(buf); ! filearg[0] = fetchname(buf, 0, FALSE); } if (filearg[0] == NULL) { ask("No file found--skip this patch? [n] "); --- 166,179 ---- if (force || batch) { say("No file to patch. Skipping...\n"); filearg[0] = savestr(bestguess); ! skip_rest_of_patch = true; ! return true; } ask("File to patch: "); if (*buf != '\n') { free(bestguess); bestguess = savestr(buf); ! filearg[0] = fetchname(buf, 0, false); } if (filearg[0] == NULL) { ask("No file found--skip this patch? [n] "); *************** *** 186,197 **** continue; if (verbose) say("Skipping patch...\n"); ! filearg[0] = fetchname(bestguess, 0, TRUE); ! skip_rest_of_patch = TRUE; ! return TRUE; } } ! return TRUE; } /* Determine what kind of diff is in the remaining part of the patch file. */ --- 181,192 ---- continue; if (verbose) say("Skipping patch...\n"); ! filearg[0] = fetchname(bestguess, 0, true); ! skip_rest_of_patch = true; ! return true; } } ! return true; } /* Determine what kind of diff is in the remaining part of the patch file. */ *************** *** 200,208 **** intuit_diff_type(void) { long this_line = 0, previous_line; ! long first_command_line = -1, fcl_line; ! bool last_line_was_command = FALSE, this_is_a_command = FALSE; ! bool stars_last_line = FALSE, stars_this_line = FALSE; char *s, *t; char *indtmp = NULL; char *oldtmp = NULL; --- 195,204 ---- intuit_diff_type(void) { long this_line = 0, previous_line; ! long first_command_line = -1; ! LINENUM fcl_line = -1; ! bool last_line_was_command = false, this_is_a_command = false; ! bool stars_last_line = false, stars_this_line = false; char *s, *t; char *indtmp = NULL; char *oldtmp = NULL; *************** *** 213,219 **** int indent, retval; bool no_filearg = (filearg[0] == NULL); ! ok_to_create_file = FALSE; fseek(pfp, p_base, SEEK_SET); p_input_line = p_bline - 1; for (;;) { --- 209,215 ---- int indent, retval; bool no_filearg = (filearg[0] == NULL); ! ok_to_create_file = false; fseek(pfp, p_base, SEEK_SET); p_input_line = p_bline - 1; for (;;) { *************** *** 283,289 **** } if ((!diff_type || diff_type == UNI_DIFF) && strnEQ(s, "@@ -", 4)) { if (!atol(s + 3)) ! ok_to_create_file = TRUE; p_indent = indent; p_start = this_line; p_sline = p_input_line; --- 279,285 ---- } if ((!diff_type || diff_type == UNI_DIFF) && strnEQ(s, "@@ -", 4)) { if (!atol(s + 3)) ! ok_to_create_file = true; p_indent = indent; p_start = this_line; p_sline = p_input_line; *************** *** 294,300 **** if ((!diff_type || diff_type == CONTEXT_DIFF) && stars_last_line && strnEQ(s, "*** ", 4)) { if (!atol(s + 4)) ! ok_to_create_file = TRUE; /* * if this is a new context diff the character just * before --- 290,296 ---- if ((!diff_type || diff_type == CONTEXT_DIFF) && stars_last_line && strnEQ(s, "*** ", 4)) { if (!atol(s + 4)) ! ok_to_create_file = true; /* * if this is a new context diff the character just * before *************** *** 345,356 **** if (filearg[0] != NULL) bestguess = savestr(filearg[0]); else if (indtmp != NULL) ! bestguess = fetchname(indtmp, strippath, TRUE); else { if (oldtmp != NULL) ! oldname = fetchname(oldtmp, strippath, TRUE); if (newtmp != NULL) ! newname = fetchname(newtmp, strippath, TRUE); if (oldname && newname) { if (strlen(oldname) < strlen(newname)) bestguess = savestr(oldname); --- 341,352 ---- if (filearg[0] != NULL) bestguess = savestr(filearg[0]); else if (indtmp != NULL) ! bestguess = fetchname(indtmp, strippath, true); else { if (oldtmp != NULL) ! oldname = fetchname(oldtmp, strippath, true); if (newtmp != NULL) ! newname = fetchname(newtmp, strippath, true); if (oldname && newname) { if (strlen(oldname) < strlen(newname)) bestguess = savestr(oldname); *************** *** 388,400 **** { char *ret; ! assert(p_base <= file_pos); if (verbose && p_base < file_pos) { fseek(pfp, p_base, SEEK_SET); say("The text leading up to this was:\n--------------------------\n"); while (ftell(pfp) < file_pos) { ret = fgets(buf, sizeof buf, pfp); ! assert(ret != NULL); say("|%s", buf); } say("--------------------------\n"); --- 384,398 ---- { char *ret; ! if (p_base > file_pos) ! fatal("Internal error: seek %ld>%ld\n", p_base, file_pos); if (verbose && p_base < file_pos) { fseek(pfp, p_base, SEEK_SET); say("The text leading up to this was:\n--------------------------\n"); while (ftell(pfp) < file_pos) { ret = fgets(buf, sizeof buf, pfp); ! if (ret == NULL) ! fatal("Unexpected end of file\n"); say("|%s", buf); } say("--------------------------\n"); *************** *** 426,437 **** c = fgetc(pfp); } while (c != EOF && c != '\n'); ! return TRUE; } if (c != EOF) fseek(pfp, -1L, SEEK_CUR); ! return FALSE; } /* --- 424,435 ---- c = fgetc(pfp); } while (c != EOF && c != '\n'); ! return true; } if (c != EOF) fseek(pfp, -1L, SEEK_CUR); ! return false; } /* *************** *** 461,467 **** free(p_line[p_end]); p_end--; } - assert(p_end == -1); p_efake = -1; p_max = hunkmax; /* gets reduced when --- found */ --- 459,464 ---- *************** *** 469,477 **** line_beginning = ftell(pfp); repl_beginning = 0; fillcnt = 0; ! ptrn_spaces_eaten = FALSE; ! repl_could_be_missing = TRUE; ! repl_missing = FALSE; repl_backtrack_position = 0; ptrn_copiable = 0; --- 466,474 ---- line_beginning = ftell(pfp); repl_beginning = 0; fillcnt = 0; ! ptrn_spaces_eaten = false; ! repl_could_be_missing = true; ! repl_missing = false; repl_backtrack_position = 0; ptrn_copiable = 0; *************** *** 479,485 **** p_input_line++; if (ret == NULL || strnNE(buf, "********", 8)) { next_intuit_at(line_beginning, p_input_line); ! return FALSE; } p_context = 100; p_hunk_beg = p_input_line + 1; --- 476,482 ---- p_input_line++; if (ret == NULL || strnNE(buf, "********", 8)) { next_intuit_at(line_beginning, p_input_line); ! return false; } p_context = 100; p_hunk_beg = p_input_line + 1; *************** *** 493,513 **** strlcpy(buf, " \n", sizeof buf); } else { if (repl_beginning && repl_could_be_missing) { ! repl_missing = TRUE; goto hunk_done; } fatal("unexpected end of file in patch\n"); } } p_end++; ! assert(p_end < hunkmax); p_char[p_end] = *buf; p_line[p_end] = NULL; switch (*buf) { case '*': if (strnEQ(buf, "********", 8)) { if (repl_beginning && repl_could_be_missing) { ! repl_missing = TRUE; goto hunk_done; } else fatal("unexpected end of hunk " --- 490,512 ---- strlcpy(buf, " \n", sizeof buf); } else { if (repl_beginning && repl_could_be_missing) { ! repl_missing = true; goto hunk_done; } fatal("unexpected end of file in patch\n"); } } p_end++; ! if (p_end >= hunkmax) ! fatal("Internal error: hunk larger than hunk " ! "buffer size"); p_char[p_end] = *buf; p_line[p_end] = NULL; switch (*buf) { case '*': if (strnEQ(buf, "********", 8)) { if (repl_beginning && repl_could_be_missing) { ! repl_missing = true; goto hunk_done; } else fatal("unexpected end of hunk " *************** *** 516,522 **** } if (p_end != 0) { if (repl_beginning && repl_could_be_missing) { ! repl_missing = TRUE; goto hunk_done; } fatal("unexpected *** at line %ld: %s", --- 515,521 ---- } if (p_end != 0) { if (repl_beginning && repl_could_be_missing) { ! repl_missing = true; goto hunk_done; } fatal("unexpected *** at line %ld: %s", *************** *** 526,532 **** p_line[p_end] = savestr(buf); if (out_of_mem) { p_end--; ! return FALSE; } for (s = buf; *s && !isdigit(*s); s++) ; --- 525,531 ---- p_line[p_end] = savestr(buf); if (out_of_mem) { p_end--; ! return false; } for (s = buf; *s && !isdigit(*s); s++) ; *************** *** 574,580 **** } else { if (repl_beginning) { if (repl_could_be_missing) { ! repl_missing = TRUE; goto hunk_done; } fatal("duplicate \"---\" at line %ld--check line numbers at line %ld\n", --- 573,579 ---- } else { if (repl_beginning) { if (repl_could_be_missing) { ! repl_missing = true; goto hunk_done; } fatal("duplicate \"---\" at line %ld--check line numbers at line %ld\n", *************** *** 594,600 **** p_line[p_end] = savestr(buf); if (out_of_mem) { p_end--; ! return FALSE; } p_char[p_end] = '='; for (s = buf; *s && !isdigit(*s); s++) --- 593,599 ---- p_line[p_end] = savestr(buf); if (out_of_mem) { p_end--; ! return false; } p_char[p_end] = '='; for (s = buf; *s && !isdigit(*s); s++) *************** *** 625,644 **** grow_hunkmax(); if (p_repl_lines != ptrn_copiable && (p_context != 0 || p_repl_lines != 1)) ! repl_could_be_missing = FALSE; break; } goto change_line; case '+': case '!': ! repl_could_be_missing = FALSE; change_line: if (buf[1] == '\n' && canonicalize) strlcpy(buf + 1, " \n", sizeof buf - 1); if (!isspace(buf[1]) && buf[1] != '>' && buf[1] != '<' && repl_beginning && repl_could_be_missing) { ! repl_missing = TRUE; goto hunk_done; } if (context >= 0) { --- 624,643 ---- grow_hunkmax(); if (p_repl_lines != ptrn_copiable && (p_context != 0 || p_repl_lines != 1)) ! repl_could_be_missing = false; break; } goto change_line; case '+': case '!': ! repl_could_be_missing = false; change_line: if (buf[1] == '\n' && canonicalize) strlcpy(buf + 1, " \n", sizeof buf - 1); if (!isspace(buf[1]) && buf[1] != '>' && buf[1] != '<' && repl_beginning && repl_could_be_missing) { ! repl_missing = true; goto hunk_done; } if (context >= 0) { *************** *** 649,655 **** p_line[p_end] = savestr(buf + 2); if (out_of_mem) { p_end--; ! return FALSE; } if (p_end == p_ptrn_lines) { if (remove_special_line()) { --- 648,654 ---- p_line[p_end] = savestr(buf + 2); if (out_of_mem) { p_end--; ! return false; } if (p_end == p_ptrn_lines) { if (remove_special_line()) { *************** *** 665,677 **** if (repl_beginning && repl_could_be_missing && (!ptrn_spaces_eaten || diff_type == NEW_CONTEXT_DIFF)) { ! repl_missing = TRUE; goto hunk_done; } p_line[p_end] = savestr(buf); if (out_of_mem) { p_end--; ! return FALSE; } if (p_end != p_ptrn_lines + 1) { ptrn_spaces_eaten |= (repl_beginning != 0); --- 664,676 ---- if (repl_beginning && repl_could_be_missing && (!ptrn_spaces_eaten || diff_type == NEW_CONTEXT_DIFF)) { ! repl_missing = true; goto hunk_done; } p_line[p_end] = savestr(buf); if (out_of_mem) { p_end--; ! return false; } if (p_end != p_ptrn_lines + 1) { ptrn_spaces_eaten |= (repl_beginning != 0); *************** *** 684,690 **** case ' ': if (!isspace(buf[1]) && repl_beginning && repl_could_be_missing) { ! repl_missing = TRUE; goto hunk_done; } context++; --- 683,689 ---- case ' ': if (!isspace(buf[1]) && repl_beginning && repl_could_be_missing) { ! repl_missing = true; goto hunk_done; } context++; *************** *** 693,704 **** p_line[p_end] = savestr(buf + 2); if (out_of_mem) { p_end--; ! return FALSE; } break; default: if (repl_beginning && repl_could_be_missing) { ! repl_missing = TRUE; goto hunk_done; } malformed(); --- 692,703 ---- p_line[p_end] = savestr(buf + 2); if (out_of_mem) { p_end--; ! return false; } break; default: if (repl_beginning && repl_could_be_missing) { ! repl_missing = true; goto hunk_done; } malformed(); *************** *** 783,790 **** printf("fillsrc %ld, filldst %ld, rb %ld, e+1 %ld\n", fillsrc, filldst, repl_beginning, p_end + 1); #endif ! assert(fillsrc == p_end + 1 || fillsrc == repl_beginning); ! assert(filldst == p_end + 1 || filldst == repl_beginning); } if (p_line[p_end] != NULL) { if (remove_special_line()) { --- 782,791 ---- printf("fillsrc %ld, filldst %ld, rb %ld, e+1 %ld\n", fillsrc, filldst, repl_beginning, p_end + 1); #endif ! if (fillsrc != p_end + 1 && fillsrc != repl_beginning) ! malformed(); ! if (filldst != p_end + 1 && filldst != repl_beginning) ! malformed(); } if (p_line[p_end] != NULL) { if (remove_special_line()) { *************** *** 802,808 **** p_input_line++; if (ret == NULL || strnNE(buf, "@@ -", 4)) { next_intuit_at(line_beginning, p_input_line); ! return FALSE; } s = buf + 4; if (!*s) --- 803,809 ---- p_input_line++; if (ret == NULL || strnNE(buf, "@@ -", 4)) { next_intuit_at(line_beginning, p_input_line); ! return false; } s = buf + 4; if (!*s) *************** *** 846,852 **** p_line[0] = savestr(buf); if (out_of_mem) { p_end = -1; ! return FALSE; } p_char[0] = '*'; snprintf(buf, sizeof buf, "--- %ld,%ld ----\n", p_newfirst, --- 847,853 ---- p_line[0] = savestr(buf); if (out_of_mem) { p_end = -1; ! return false; } p_char[0] = '*'; snprintf(buf, sizeof buf, "--- %ld,%ld ----\n", p_newfirst, *************** *** 854,860 **** p_line[filldst] = savestr(buf); if (out_of_mem) { p_end = 0; ! return FALSE; } p_char[filldst++] = '='; p_context = 100; --- 855,861 ---- p_line[filldst] = savestr(buf); if (out_of_mem) { p_end = 0; ! return false; } p_char[filldst++] = '='; p_context = 100; *************** *** 883,889 **** while (--filldst > p_ptrn_lines) free(p_line[filldst]); p_end = fillsrc - 1; ! return FALSE; } switch (ch) { case '-': --- 884,890 ---- while (--filldst > p_ptrn_lines) free(p_line[filldst]); p_end = fillsrc - 1; ! return false; } switch (ch) { case '-': *************** *** 922,928 **** while (--filldst > p_ptrn_lines) free(p_line[filldst]); p_end = fillsrc - 1; ! return FALSE; } /* FALL THROUGH */ case '+': --- 923,929 ---- while (--filldst > p_ptrn_lines) free(p_line[filldst]); p_end = fillsrc - 1; ! return false; } /* FALL THROUGH */ case '+': *************** *** 964,970 **** p_input_line++; if (ret == NULL || !isdigit(*buf)) { next_intuit_at(line_beginning, p_input_line); ! return FALSE; } p_first = (LINENUM) atol(buf); for (s = buf; isdigit(*s); s++) --- 965,971 ---- p_input_line++; if (ret == NULL || !isdigit(*buf)) { next_intuit_at(line_beginning, p_input_line); ! return false; } p_first = (LINENUM) atol(buf); for (s = buf; isdigit(*s); s++) *************** *** 1000,1006 **** p_line[0] = savestr(buf); if (out_of_mem) { p_end = -1; ! return FALSE; } p_char[0] = '*'; for (i = 1; i <= p_ptrn_lines; i++) { --- 1001,1007 ---- p_line[0] = savestr(buf); if (out_of_mem) { p_end = -1; ! return false; } p_char[0] = '*'; for (i = 1; i <= p_ptrn_lines; i++) { *************** *** 1015,1021 **** p_line[i] = savestr(buf + 2); if (out_of_mem) { p_end = i - 1; ! return FALSE; } p_len[i] = strlen(p_line[i]); p_char[i] = '-'; --- 1016,1022 ---- p_line[i] = savestr(buf + 2); if (out_of_mem) { p_end = i - 1; ! return false; } p_len[i] = strlen(p_line[i]); p_char[i] = '-'; *************** *** 1039,1045 **** p_line[i] = savestr(buf); if (out_of_mem) { p_end = i - 1; ! return FALSE; } p_char[i] = '='; for (i++; i <= p_end; i++) { --- 1040,1046 ---- p_line[i] = savestr(buf); if (out_of_mem) { p_end = i - 1; ! return false; } p_char[i] = '='; for (i++; i <= p_end; i++) { *************** *** 1054,1060 **** p_line[i] = savestr(buf + 2); if (out_of_mem) { p_end = i - 1; ! return FALSE; } p_len[i] = strlen(p_line[i]); p_char[i] = '+'; --- 1055,1061 ---- p_line[i] = savestr(buf + 2); if (out_of_mem) { p_end = i - 1; ! return false; } p_len[i] = strlen(p_line[i]); p_char[i] = '+'; *************** *** 1086,1092 **** #endif if (p_end + 1 < hunkmax)/* paranoia reigns supreme... */ p_char[p_end + 1] = '^'; /* add a stopper for apply_hunk */ ! return TRUE; } /* --- 1087,1093 ---- #endif if (p_end + 1 < hunkmax)/* paranoia reigns supreme... */ p_char[p_end + 1] = '^'; /* add a stopper for apply_hunk */ ! return true; } /* *************** *** 1124,1130 **** char *tp_char; /* +, -, and ! */ LINENUM i; LINENUM n; ! bool blankline = FALSE; char *s; i = p_first; --- 1125,1131 ---- char *tp_char; /* +, -, and ! */ LINENUM i; LINENUM n; ! bool blankline = false; char *s; i = p_first; *************** *** 1140,1163 **** p_len = NULL; p_char = NULL; set_hunkmax(); ! if (p_line == NULL ||p_len == NULL ||p_char == NULL) { ! if (p_line == NULL) /* XXX */ ! free(p_line); p_line = tp_line; ! if (p_len == NULL) /* XXX */ ! free(p_len); p_len = tp_len; ! if (p_char == NULL) /* XXX */ ! free(p_char); p_char = tp_char; ! return FALSE; /* not enough memory to swap hunk! */ } /* now turn the new into the old */ i = p_ptrn_lines + 1; if (tp_char[i] == '\n') { /* account for possible blank line */ ! blankline = TRUE; i++; } if (p_efake >= 0) { /* fix non-freeable ptr range */ --- 1141,1161 ---- p_len = NULL; p_char = NULL; set_hunkmax(); ! if (p_line == NULL || p_len == NULL || p_char == NULL) { ! free(p_line); p_line = tp_line; ! free(p_len); p_len = tp_len; ! free(p_char); p_char = tp_char; ! return false; /* not enough memory to swap hunk! */ } /* now turn the new into the old */ i = p_ptrn_lines + 1; if (tp_char[i] == '\n') { /* account for possible blank line */ ! blankline = true; i++; } if (p_efake >= 0) { /* fix non-freeable ptr range */ *************** *** 1182,1188 **** p_len[n] = tp_len[i]; n++; } ! assert(p_char[0] == '='); p_char[0] = '*'; for (s = p_line[0]; *s; s++) if (*s == '-') --- 1180,1188 ---- p_len[n] = tp_len[i]; n++; } ! if (p_char[0] != '=') ! fatal("Malformed patch at line %ld: expected '=' found '%c'\n", ! p_input_line, p_char[0]); p_char[0] = '*'; for (s = p_line[0]; *s; s++) if (*s == '-') *************** *** 1190,1196 **** /* now turn the old into the new */ ! assert(tp_char[0] == '*'); tp_char[0] = '='; for (s = tp_line[0]; *s; s++) if (*s == '*') --- 1190,1198 ---- /* now turn the old into the new */ ! if (p_char[0] != '*') ! fatal("Malformed patch at line %ld: expected '*' found '%c'\n", ! p_input_line, p_char[0]); tp_char[0] = '='; for (s = tp_line[0]; *s; s++) if (*s == '*') *************** *** 1202,1219 **** p_char[n] = '+'; p_len[n] = tp_len[i]; } ! assert(i == p_ptrn_lines + 1); i = p_ptrn_lines; p_ptrn_lines = p_repl_lines; p_repl_lines = i; ! if (tp_line == NULL) /* XXX */ ! free(tp_line); ! if (tp_len == NULL) /* XXX */ ! free(tp_len); ! if (tp_char == NULL) /* XXX */ ! free(tp_char); ! return TRUE; } /* --- 1204,1224 ---- p_char[n] = '+'; p_len[n] = tp_len[i]; } ! ! if (i != p_ptrn_lines + 1) ! fatal("Malformed patch at line %ld: expected %ld lines, " ! "got %ld\n", ! p_input_line, p_ptrn_lines + 1, i); ! i = p_ptrn_lines; p_ptrn_lines = p_repl_lines; p_repl_lines = i; ! free(tp_line); ! free(tp_len); ! free(tp_char); ! ! return true; } /* *************** *** 1316,1321 **** --- 1321,1327 ---- long beginning_of_this_line; FILE *pipefp; + pipefp = NULL; if (!skip_rest_of_patch) { if (copy_file(filearg[0], TMPOUTNAME) < 0) { unlink(TMPOUTNAME); *************** *** 1337,1348 **** /* POSIX defines allowed commands as {a,c,d,i,s} */ if (isdigit(*buf) && (*t == 'a' || *t == 'c' || *t == 'd' || *t == 'i' || *t == 's')) { ! if (!skip_rest_of_patch) fputs(buf, pipefp); if (*t != 'd') { while (pgets(buf, sizeof buf, pfp) != NULL) { p_input_line++; ! if (!skip_rest_of_patch) fputs(buf, pipefp); if (strEQ(buf, ".\n")) break; --- 1343,1354 ---- /* POSIX defines allowed commands as {a,c,d,i,s} */ if (isdigit(*buf) && (*t == 'a' || *t == 'c' || *t == 'd' || *t == 'i' || *t == 's')) { ! if (pipefp != NULL) fputs(buf, pipefp); if (*t != 'd') { while (pgets(buf, sizeof buf, pfp) != NULL) { p_input_line++; ! if (pipefp != NULL) fputs(buf, pipefp); if (strEQ(buf, ".\n")) break; *************** *** 1353,1359 **** break; } } ! if (skip_rest_of_patch) return; fprintf(pipefp, "w\n"); fprintf(pipefp, "q\n"); --- 1359,1365 ---- break; } } ! if (pipefp == NULL) return; fprintf(pipefp, "w\n"); fprintf(pipefp, "q\n"); *************** *** 1362,1368 **** ignore_signals(); if (!check_only) { if (move_file(TMPOUTNAME, outname) < 0) { ! toutkeep = TRUE; chmod(TMPOUTNAME, filemode); } else chmod(outname, filemode); --- 1368,1374 ---- ignore_signals(); if (!check_only) { if (move_file(TMPOUTNAME, outname) < 0) { ! toutkeep = true; chmod(TMPOUTNAME, filemode); } else chmod(outname, filemode);