Module Name: src Committed By: manu Date: Fri Jul 12 15:48:39 UTC 2024
Modified Files: src/usr.bin/patch: patch.c pch.c pch.h Log Message: Let patch(1) handle lines of length beyond INT16_MAX Borrowed from OpenBSD https://marc.info/?l=openbsd-bugs&m=168907249732754 To generate a diff of this commit: cvs rdiff -u -r1.34 -r1.35 src/usr.bin/patch/patch.c cvs rdiff -u -r1.33 -r1.34 src/usr.bin/patch/pch.c cvs rdiff -u -r1.10 -r1.11 src/usr.bin/patch/pch.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/patch/patch.c diff -u src/usr.bin/patch/patch.c:1.34 src/usr.bin/patch/patch.c:1.35 --- src/usr.bin/patch/patch.c:1.34 Fri Jun 16 11:27:00 2023 +++ src/usr.bin/patch/patch.c Fri Jul 12 15:48:39 2024 @@ -1,7 +1,7 @@ /* * $OpenBSD: patch.c,v 1.45 2007/04/18 21:52:24 sobrado Exp $ * $DragonFly: src/usr.bin/patch/patch.c,v 1.10 2008/08/10 23:39:56 joerg Exp $ - * $NetBSD: patch.c,v 1.34 2023/06/16 11:27:00 wiz Exp $ + * $NetBSD: patch.c,v 1.35 2024/07/12 15:48:39 manu Exp $ */ /* @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: patch.c,v 1.34 2023/06/16 11:27:00 wiz Exp $"); +__RCSID("$NetBSD: patch.c,v 1.35 2024/07/12 15:48:39 manu Exp $"); #include <sys/types.h> #include <sys/stat.h> @@ -106,7 +106,7 @@ static void copy_till(LINENUM, bool); static bool spew_output(void); static void dump_line(LINENUM, bool); static bool patch_match(LINENUM, LINENUM, LINENUM); -static bool similar(const char *, const char *, int); +static bool similar(const char *, const char *, ssize_t); __dead static void usage(void); /* true if -E was specified on command line. */ @@ -1027,7 +1027,7 @@ patch_match(LINENUM base, LINENUM offset LINENUM pat_lines = pch_ptrn_lines() - fuzz; const char *ilineptr; const char *plineptr; - short plinelen; + ssize_t plinelen; for (iline = base + offset + fuzz; pline <= pat_lines; pline++, iline++) { ilineptr = ifetch(iline, offset >= 0); @@ -1063,7 +1063,7 @@ patch_match(LINENUM base, LINENUM offset * Do two lines match with canonicalized white space? */ static bool -similar(const char *a, const char *b, int len) +similar(const char *a, const char *b, ssize_t len) { while (len) { if (isspace((unsigned char)*b)) { /* whitespace (or \n) to match? */ Index: src/usr.bin/patch/pch.c diff -u src/usr.bin/patch/pch.c:1.33 src/usr.bin/patch/pch.c:1.34 --- src/usr.bin/patch/pch.c:1.33 Fri Jun 16 23:31:53 2023 +++ src/usr.bin/patch/pch.c Fri Jul 12 15:48:39 2024 @@ -1,7 +1,7 @@ /* * $OpenBSD: pch.c,v 1.37 2007/09/02 15:19:33 deraadt Exp $ * $DragonFly: src/usr.bin/patch/pch.c,v 1.6 2008/08/10 23:35:40 joerg Exp $ - * $NetBSD: pch.c,v 1.33 2023/06/16 23:31:53 wiz Exp $ + * $NetBSD: pch.c,v 1.34 2024/07/12 15:48:39 manu Exp $ */ /* @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: pch.c,v 1.33 2023/06/16 23:31:53 wiz Exp $"); +__RCSID("$NetBSD: pch.c,v 1.34 2024/07/12 15:48:39 manu Exp $"); #include <sys/types.h> #include <sys/stat.h> @@ -61,7 +61,7 @@ static LINENUM p_max; /* max allowed va static LINENUM p_context = 3; /* # of context lines */ static LINENUM p_input_line = 0; /* current line # from patch file */ static char **p_line = NULL;/* the text of the hunk */ -static short *p_len = NULL; /* length of each line */ +static ssize_t *p_len = NULL; /* length of each line */ static char *p_char = NULL; /* +, -, and ! */ static int hunkmax = INITHUNKMAX; /* size of above arrays to begin with */ static int p_indent; /* indent to patch */ @@ -135,7 +135,7 @@ set_hunkmax(void) if (p_line == NULL) p_line = calloc((size_t) hunkmax, sizeof(char *)); if (p_len == NULL) - p_len = calloc((size_t) hunkmax, sizeof(short)); + p_len = calloc((size_t) hunkmax, sizeof(ssize_t)); if (p_char == NULL) p_char = calloc((size_t) hunkmax, sizeof(char)); } @@ -148,7 +148,7 @@ grow_hunkmax(void) { int new_hunkmax; char **new_p_line; - short *new_p_len; + ssize_t *new_p_len; char *new_p_char; new_hunkmax = hunkmax * 2; @@ -160,7 +160,7 @@ grow_hunkmax(void) if (new_p_line == NULL) free(p_line); - new_p_len = pch_realloc(p_len, new_hunkmax, sizeof(short)); + new_p_len = pch_realloc(p_len, new_hunkmax, sizeof(ssize_t)); if (new_p_len == NULL) free(p_len); @@ -1207,7 +1207,7 @@ bool pch_swap(void) { char **tp_line; /* the text of the hunk */ - short *tp_len; /* length of each line */ + ssize_t *tp_len; /* length of each line */ char *tp_char; /* +, -, and ! */ LINENUM i; LINENUM n; @@ -1364,7 +1364,7 @@ pch_context(void) /* * Return the length of a particular patch line. */ -short +ssize_t pch_line_len(LINENUM line) { return p_len[line]; Index: src/usr.bin/patch/pch.h diff -u src/usr.bin/patch/pch.h:1.10 src/usr.bin/patch/pch.h:1.11 --- src/usr.bin/patch/pch.h:1.10 Fri Sep 19 18:33:34 2008 +++ src/usr.bin/patch/pch.h Fri Jul 12 15:48:39 2024 @@ -1,7 +1,7 @@ /* * $OpenBSD: pch.h,v 1.9 2003/10/31 20:20:45 millert Exp $ * $DragonFly: src/usr.bin/patch/pch.h,v 1.1 2004/09/24 18:44:28 joerg Exp $ - * $NetBSD: pch.h,v 1.10 2008/09/19 18:33:34 joerg Exp $ + * $NetBSD: pch.h,v 1.11 2024/07/12 15:48:39 manu Exp $ */ /* @@ -47,7 +47,7 @@ bool there_is_another_patch(void); bool another_hunk(void); bool pch_swap(void); char *pfetch(LINENUM); -short pch_line_len(LINENUM); +ssize_t pch_line_len(LINENUM); LINENUM pch_first(void); LINENUM pch_ptrn_lines(void); LINENUM pch_newfirst(void);