diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2003-07-23 07:31:22 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2003-07-23 07:31:22 +0000 |
commit | edd697aa986dd4291faaa8ae89cd9a3bde3bd40c (patch) | |
tree | b810a1fe4fd7e7406e1313d91c78e2247b1c7803 | |
parent | 2caeeadcb630018c9b342088886a2a4dfe32f4e1 (diff) |
New version of invalid line number fix. Passes patch(1) regressions.
ok millert@ deraadt@
-rw-r--r-- | usr.bin/patch/inp.c | 6 | ||||
-rw-r--r-- | usr.bin/patch/patch.c | 23 |
2 files changed, 19 insertions, 10 deletions
diff --git a/usr.bin/patch/inp.c b/usr.bin/patch/inp.c index f31d6e6b448..4b0fe822c0f 100644 --- a/usr.bin/patch/inp.c +++ b/usr.bin/patch/inp.c @@ -1,7 +1,7 @@ -/* $OpenBSD: inp.c,v 1.17 2003/07/22 17:52:20 deraadt Exp $ */ +/* $OpenBSD: inp.c,v 1.18 2003/07/23 07:31:21 otto Exp $ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: inp.c,v 1.17 2003/07/22 17:52:20 deraadt Exp $"; +static const char rcsid[] = "$OpenBSD: inp.c,v 1.18 2003/07/23 07:31:21 otto Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -328,7 +328,7 @@ ifetch(LINENUM line, int whichbuf) { if (line < 1 || line > input_lines) { say("No such line %ld in input file, ignoring\n", line); - return ""; + return NULL; } if (using_plan_a) return i_ptr[line]; diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c index 8095625113f..8c067e55a7d 100644 --- a/usr.bin/patch/patch.c +++ b/usr.bin/patch/patch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: patch.c,v 1.25 2003/07/22 20:48:58 millert Exp $ */ +/* $OpenBSD: patch.c,v 1.26 2003/07/23 07:31:21 otto Exp $ */ /* * patch - a program to apply diffs to original files @@ -27,7 +27,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: patch.c,v 1.25 2003/07/22 20:48:58 millert Exp $"; +static const char rcsid[] = "$OpenBSD: patch.c,v 1.26 2003/07/23 07:31:21 otto Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -788,8 +788,11 @@ dump_line(LINENUM line) { char *s, R_newline = '\n'; + s = ifetch(line, 0); + if (s == NULL) + return; /* Note: string is not null terminated. */ - for (s=ifetch(line, 0); putc(*s, ofp) != R_newline; s++) + for (; putc(*s, ofp) != R_newline; s++) ; } @@ -802,14 +805,20 @@ patch_match(LINENUM base, LINENUM offset, LINENUM fuzz) LINENUM pline = 1 + fuzz; LINENUM iline; LINENUM pat_lines = pch_ptrn_lines() - fuzz; + char *ilineptr; + char *plineptr; + short plinelen; for (iline = base + offset + fuzz; pline <= pat_lines; pline++, iline++) { + ilineptr = ifetch(iline, offset >= 0); + if (ilineptr == NULL) + return FALSE; + plineptr = pfetch(pline); + plinelen = pch_line_len(pline); if (canonicalize) { - if (!similar(ifetch(iline, (offset >= 0)), - pfetch(pline), pch_line_len(pline))) + if (!similar(ilineptr, plineptr, plinelen)) return FALSE; - } else if (strnNE(ifetch(iline, (offset >= 0)), - pfetch(pline), pch_line_len(pline))) + } else if (strnNE(ilineptr, plineptr, plinelen)) return FALSE; } return TRUE; |