diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2009-06-07 08:39:14 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2009-06-07 08:39:14 +0000 |
commit | 8896fb155a60da615a44f9b4f57e849d2d826fbb (patch) | |
tree | 9994931387b3cfb5f8e8de66ec0c5f2e63c4132b /usr.bin | |
parent | cf7eb25db5ce1f28444b090d61344d49803d57d3 (diff) |
More cvs/diff/rcs convergence:
1. Mostly variable/function renaming, SIZE_T_MAX->SIZE_MAX, and
spacing.
2. One strchr -> strncspn.
3. diff had a weird thing where it set file[12] = ofile[12] but
never updated file or ofile, then if file and ofile were different
it freed it. I removed it.
OK millert
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/cvs/commit.c | 4 | ||||
-rw-r--r-- | usr.bin/cvs/diff.c | 4 | ||||
-rw-r--r-- | usr.bin/cvs/diff.h | 6 | ||||
-rw-r--r-- | usr.bin/cvs/diff3.c | 8 | ||||
-rw-r--r-- | usr.bin/cvs/diff_internals.c | 22 | ||||
-rw-r--r-- | usr.bin/cvs/import.c | 4 | ||||
-rw-r--r-- | usr.bin/cvs/rcs.c | 4 | ||||
-rw-r--r-- | usr.bin/cvs/xmalloc.c | 10 | ||||
-rw-r--r-- | usr.bin/diff/diff.c | 38 | ||||
-rw-r--r-- | usr.bin/diff/diff.h | 4 | ||||
-rw-r--r-- | usr.bin/diff/diffdir.c | 6 | ||||
-rw-r--r-- | usr.bin/diff/diffreg.c | 103 | ||||
-rw-r--r-- | usr.bin/diff/xmalloc.c | 20 | ||||
-rw-r--r-- | usr.bin/diff/xmalloc.h | 3 | ||||
-rw-r--r-- | usr.bin/rcs/diff.c | 6 | ||||
-rw-r--r-- | usr.bin/rcs/xmalloc.c | 10 |
16 files changed, 128 insertions, 124 deletions
diff --git a/usr.bin/cvs/commit.c b/usr.bin/cvs/commit.c index 36f2b606c56..31dc8870b81 100644 --- a/usr.bin/cvs/commit.c +++ b/usr.bin/cvs/commit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: commit.c,v 1.148 2009/06/06 14:17:27 ray Exp $ */ +/* $OpenBSD: commit.c,v 1.149 2009/06/07 08:39:13 ray Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * Copyright (c) 2006 Xavier Santolaria <xsa@openbsd.org> @@ -760,7 +760,7 @@ commit_diff(struct cvs_file *cf, RCSNUM *rev, int reverse) fd2 = f; } - if (cvs_diffreg(p1, p2, fd1, fd2, b, D_FORCEASCII) == D_ERROR) + if (diffreg(p1, p2, fd1, fd2, b, D_FORCEASCII) == D_ERROR) fatal("commit_diff: failed to get RCS patch"); close(fd1); diff --git a/usr.bin/cvs/diff.c b/usr.bin/cvs/diff.c index 89bd7206255..956aa0470a1 100644 --- a/usr.bin/cvs/diff.c +++ b/usr.bin/cvs/diff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diff.c,v 1.154 2009/06/06 14:17:27 ray Exp $ */ +/* $OpenBSD: diff.c,v 1.155 2009/06/07 08:39:13 ray Exp $ */ /* * Copyright (c) 2008 Tobias Stoeckmann <tobias@openbsd.org> * Copyright (c) 2006 Joris Vink <joris@openbsd.org> @@ -566,7 +566,7 @@ cvs_diff_local(struct cvs_file *cf) fatal("cannot open %s", CVS_PATH_DEVNULL); } - if (cvs_diffreg(p1 != NULL ? cf->file_path : CVS_PATH_DEVNULL, + if (diffreg(p1 != NULL ? cf->file_path : CVS_PATH_DEVNULL, p2 != NULL ? cf->file_path : CVS_PATH_DEVNULL, fd1, fd2, NULL, dflags) == D_ERROR) fatal("cvs_diff_local: failed to get RCS patch"); diff --git a/usr.bin/cvs/diff.h b/usr.bin/cvs/diff.h index 8d0fb37d330..757b272b391 100644 --- a/usr.bin/cvs/diff.h +++ b/usr.bin/cvs/diff.h @@ -1,4 +1,4 @@ -/* $OpenBSD: diff.h,v 1.19 2009/06/06 14:17:27 ray Exp $ */ +/* $OpenBSD: diff.h,v 1.20 2009/06/07 08:39:13 ray Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. * All rights reserved. @@ -89,7 +89,7 @@ #define D_IGNOREBLANKS 0x40 /* Ignore white space changes */ /* - * Status values for cvs_diffreg() return values + * Status values for diffreg() return values */ #define D_SAME 0 /* Files are the same */ #define D_DIFFER 1 /* Files are different */ @@ -104,7 +104,7 @@ void cvs_merge_file(struct cvs_file *, int); void diff_output(const char *, ...); -int cvs_diffreg(const char *, const char *, int, int, BUF *, int); +int diffreg(const char *, const char *, int, int, BUF *, int); int ed_patch_lines(struct cvs_lines *, struct cvs_lines *); extern int diff_format; diff --git a/usr.bin/cvs/diff3.c b/usr.bin/cvs/diff3.c index 87fb9f329d6..91290eaaaa1 100644 --- a/usr.bin/cvs/diff3.c +++ b/usr.bin/cvs/diff3.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diff3.c,v 1.49 2009/06/06 14:17:27 ray Exp $ */ +/* $OpenBSD: diff3.c,v 1.50 2009/06/07 08:39:13 ray Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. @@ -72,7 +72,7 @@ static const char copyright[] = #ifndef lint static const char rcsid[] = - "$OpenBSD: diff3.c,v 1.49 2009/06/06 14:17:27 ray Exp $"; + "$OpenBSD: diff3.c,v 1.50 2009/06/07 08:39:13 ray Exp $"; #endif /* not lint */ #include <ctype.h> @@ -199,8 +199,8 @@ cvs_merge_file(struct cvs_file *cf, int verbose) cvs_printf("Retrieving revision %s\n", r2); fds[4] = rcs_rev_write_stmp(cf->file_rcs, d3rev2, path3, 0); - cvs_diffreg(path1, path3, fds[2], fds[4], d1, D_FORCEASCII); - cvs_diffreg(path2, path3, fds[3], fds[4], d2, D_FORCEASCII); + diffreg(path1, path3, fds[2], fds[4], d1, D_FORCEASCII); + diffreg(path2, path3, fds[3], fds[4], d2, D_FORCEASCII); (void)xasprintf(&dp13, "%s/d13.XXXXXXXXXX", cvs_tmpdir); fds[0] = cvs_buf_write_stmp(d1, dp13, NULL); diff --git a/usr.bin/cvs/diff_internals.c b/usr.bin/cvs/diff_internals.c index 1745ff32c44..4baed471620 100644 --- a/usr.bin/cvs/diff_internals.c +++ b/usr.bin/cvs/diff_internals.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diff_internals.c,v 1.27 2009/06/06 14:17:27 ray Exp $ */ +/* $OpenBSD: diff_internals.c,v 1.28 2009/06/07 08:39:13 ray Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. * All rights reserved. @@ -295,7 +295,7 @@ u_char cup2low[256] = { }; int -cvs_diffreg(const char *file1, const char *file2, int _fd1, int _fd2, +diffreg(const char *file1, const char *file2, int _fd1, int _fd2, BUF *out, int flags) { FILE *f1, *f2; @@ -318,14 +318,14 @@ cvs_diffreg(const char *file1, const char *file2, int _fd1, int _fd2, fd1 = dup(_fd1); if (fd1 == -1) - fatal("cvs_diffreg: dup: %s", strerror(errno)); + fatal("diffreg: dup: %s", strerror(errno)); fd2 = dup(_fd2); if (fd2 == -1) - fatal("cvs_diffreg: dup: %s", strerror(errno)); + fatal("diffreg: dup: %s", strerror(errno)); if (lseek(fd1, 0, SEEK_SET) < 0) - fatal("cvs_diffreg: lseek: %s", strerror(errno)); + fatal("diffreg: lseek: %s", strerror(errno)); f1 = fdopen(fd1, "r"); if (f1 == NULL) { @@ -334,7 +334,7 @@ cvs_diffreg(const char *file1, const char *file2, int _fd1, int _fd2, } if (lseek(fd2, 0, SEEK_SET) < 0) - fatal("cvs_diffreg: lseek: %s", strerror(errno)); + fatal("diffreg: lseek: %s", strerror(errno)); f2 = fdopen(fd2, "r"); if (f2 == NULL) { @@ -544,7 +544,7 @@ stone(int *a, int n, int *b, int *c, int flags) /* XXX move the isqrt() out of the macro to avoid multiple calls */ const u_int bound = (flags & D_MINIMAL) ? UINT_MAX : - MAX(256, (u_int)isqrt(n)); + MAX(256, isqrt(n)); k = 0; c[0] = newcand(0, 0, 0); @@ -1224,7 +1224,6 @@ match_function(const long *f, int pos, FILE *fp) unsigned char buf[FUNCTION_CONTEXT_SIZE]; size_t nc; int last = lastline; - char *p; char *state = NULL; lastline = pos; @@ -1236,9 +1235,7 @@ match_function(const long *f, int pos, FILE *fp) nc = fread(buf, 1, nc, fp); if (nc > 0) { buf[nc] = '\0'; - p = strchr((const char *)buf, '\n'); - if (p != NULL) - *p = '\0'; + buf[strcspn(buf, "\n")] = '\0'; if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$') { if (begins_with(buf, "private:")) { if (!state) @@ -1250,8 +1247,7 @@ match_function(const long *f, int pos, FILE *fp) if (!state) state = " (public)"; } else { - strlcpy(lastbuf, buf, - sizeof lastbuf); + strlcpy(lastbuf, buf, sizeof lastbuf); if (state) strlcat(lastbuf, state, sizeof lastbuf); diff --git a/usr.bin/cvs/import.c b/usr.bin/cvs/import.c index 4b3ce28fb67..ede89628d17 100644 --- a/usr.bin/cvs/import.c +++ b/usr.bin/cvs/import.c @@ -1,4 +1,4 @@ -/* $OpenBSD: import.c,v 1.99 2009/06/06 14:17:27 ray Exp $ */ +/* $OpenBSD: import.c,v 1.100 2009/06/07 08:39:13 ray Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * @@ -473,7 +473,7 @@ import_get_rcsdiff(struct cvs_file *cf, RCSNUM *rev) fd2 = rcs_rev_write_stmp(cf->file_rcs, rev, p2, RCS_KWEXP_NONE); diff_format = D_RCSDIFF; - if (cvs_diffreg(p2, p1, fd2, fd1, b2, D_FORCEASCII) == D_ERROR) + if (diffreg(p2, p1, fd2, fd1, b2, D_FORCEASCII) == D_ERROR) fatal("import_get_rcsdiff: failed to get RCS patch"); close(fd1); diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c index 00afc8215e7..d1497948df5 100644 --- a/usr.bin/cvs/rcs.c +++ b/usr.bin/cvs/rcs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcs.c,v 1.290 2009/06/06 14:17:27 ray Exp $ */ +/* $OpenBSD: rcs.c,v 1.291 2009/06/07 08:39:13 ray Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -1360,7 +1360,7 @@ rcs_rev_remove(RCSFILE *rf, RCSNUM *rev) fd2 = rcs_rev_write_stmp(rf, prevrdp->rd_num, path_tmp2, 0); diff_format = D_RCSDIFF; - if (cvs_diffreg(path_tmp1, path_tmp2, + if (diffreg(path_tmp1, path_tmp2, fd1, fd2, newdiff, D_FORCEASCII) == D_ERROR) fatal("rcs_diffreg failed"); diff --git a/usr.bin/cvs/xmalloc.c b/usr.bin/cvs/xmalloc.c index 0a778cadbb7..009ccc063a9 100644 --- a/usr.bin/cvs/xmalloc.c +++ b/usr.bin/cvs/xmalloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xmalloc.c,v 1.8 2007/02/22 06:42:10 otto Exp $ */ +/* $OpenBSD: xmalloc.c,v 1.9 2009/06/07 08:39:13 ray Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland @@ -41,8 +41,8 @@ xcalloc(size_t nmemb, size_t size) if (size == 0 || nmemb == 0) fatal("xcalloc: zero size"); - if (SIZE_T_MAX / nmemb < size) - fatal("xcalloc: nmemb * size > SIZE_T_MAX"); + if (SIZE_MAX / nmemb < size) + fatal("xcalloc: nmemb * size > SIZE_MAX"); ptr = calloc(nmemb, size); if (ptr == NULL) fatal("xcalloc: out of memory (allocating %lu bytes)", @@ -58,8 +58,8 @@ xrealloc(void *ptr, size_t nmemb, size_t size) if (new_size == 0) fatal("xrealloc: zero size"); - if (SIZE_T_MAX / nmemb < size) - fatal("xrealloc: nmemb * size > SIZE_T_MAX"); + if (SIZE_MAX / nmemb < size) + fatal("xrealloc: nmemb * size > SIZE_MAX"); if (ptr == NULL) new_ptr = malloc(new_size); else diff --git a/usr.bin/diff/diff.c b/usr.bin/diff/diff.c index 373fe43518a..940124bca6c 100644 --- a/usr.bin/diff/diff.c +++ b/usr.bin/diff/diff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diff.c,v 1.52 2009/06/06 15:37:28 ray Exp $ */ +/* $OpenBSD: diff.c,v 1.53 2009/06/07 08:39:13 ray Exp $ */ /* * Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com> @@ -21,7 +21,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: diff.c,v 1.52 2009/06/06 15:37:28 ray Exp $"; +static const char rcsid[] = "$OpenBSD: diff.c,v 1.53 2009/06/07 08:39:13 ray Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -42,7 +42,7 @@ static const char rcsid[] = "$OpenBSD: diff.c,v 1.52 2009/06/06 15:37:28 ray Exp #include "xmalloc.h" int lflag, Nflag, Pflag, rflag, sflag, Tflag; -int format, context, status; +int diff_format, diff_context, status; char *start, *ifdefname, *diffargs, *label[2], *ignore_pats; struct stat stb1, stb2; struct excludes *excludes_list; @@ -104,10 +104,10 @@ main(int argc, char **argv) if (newarg) usage(); /* disallow -[0-9]+ */ else if (lastch == 'c' || lastch == 'u') - context = 0; - else if (!isdigit(lastch) || context > INT_MAX / 10) + diff_context = 0; + else if (!isdigit(lastch) || diff_context > INT_MAX / 10) usage(); - context = (context * 10) + (ch - '0'); + diff_context = (diff_context * 10) + (ch - '0'); break; case 'a': dflags |= D_FORCEASCII; @@ -117,27 +117,27 @@ main(int argc, char **argv) break; case 'C': case 'c': - format = D_CONTEXT; + diff_format = D_CONTEXT; if (optarg != NULL) { l = strtol(optarg, &ep, 10); if (*ep != '\0' || l < 0 || l >= INT_MAX) usage(); - context = (int)l; + diff_context = (int)l; } else - context = 3; + diff_context = 3; break; case 'd': dflags |= D_MINIMAL; break; case 'D': - format = D_IFDEF; + diff_format = D_IFDEF; ifdefname = optarg; break; case 'e': - format = D_EDIT; + diff_format = D_EDIT; break; case 'f': - format = D_REVERSE; + diff_format = D_REVERSE; break; case 'h': /* silently ignore for backwards compatibility */ @@ -164,7 +164,7 @@ main(int argc, char **argv) Nflag = 1; break; case 'n': - format = D_NREVERSE; + diff_format = D_NREVERSE; break; case 'p': dflags |= D_PROTOTYPE; @@ -176,7 +176,7 @@ main(int argc, char **argv) rflag = 1; break; case 'q': - format = D_BRIEF; + diff_format = D_BRIEF; break; case 'S': start = optarg; @@ -192,14 +192,14 @@ main(int argc, char **argv) break; case 'U': case 'u': - format = D_UNIFIED; + diff_format = D_UNIFIED; if (optarg != NULL) { l = strtol(optarg, &ep, 10); if (*ep != '\0' || l < 0 || l >= INT_MAX) usage(); - context = (int)l; + diff_context = (int)l; } else - context = 3; + diff_context = 3; break; case 'w': dflags |= D_IGNOREBLANKS; @@ -254,7 +254,7 @@ main(int argc, char **argv) errx(2, "can't compare - to a directory"); set_argstr(oargv, argv); if (S_ISDIR(stb1.st_mode) && S_ISDIR(stb2.st_mode)) { - if (format == D_IFDEF) + if (diff_format == D_IFDEF) errx(2, "-D option not supported with directories"); diffdir(argv[0], argv[1], dflags); } else { @@ -371,7 +371,7 @@ print_status(int val, char *path1, char *path2, char *entry) path1, entry ? entry : "", path2, entry ? entry : ""); break; case D_DIFFER: - if (format == D_BRIEF) + if (diff_format == D_BRIEF) printf("Files %s%s and %s%s differ\n", path1, entry ? entry : "", path2, entry ? entry : ""); diff --git a/usr.bin/diff/diff.h b/usr.bin/diff/diff.h index b66853302ce..5ac5f92e49a 100644 --- a/usr.bin/diff/diff.h +++ b/usr.bin/diff/diff.h @@ -1,4 +1,4 @@ -/* $OpenBSD: diff.h,v 1.31 2009/06/06 15:37:28 ray Exp $ */ +/* $OpenBSD: diff.h,v 1.32 2009/06/07 08:39:13 ray Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -85,7 +85,7 @@ struct excludes { }; extern int lflag, Nflag, Pflag, rflag, sflag, Tflag; -extern int format, context, status; +extern int diff_format, diff_context, status; extern char *start, *ifdefname, *diffargs, *label[2], *ignore_pats; extern struct stat stb1, stb2; extern struct excludes *excludes_list; diff --git a/usr.bin/diff/diffdir.c b/usr.bin/diff/diffdir.c index 64c187c2a61..83ba4c5b8c1 100644 --- a/usr.bin/diff/diffdir.c +++ b/usr.bin/diff/diffdir.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diffdir.c,v 1.33 2009/06/06 15:37:28 ray Exp $ */ +/* $OpenBSD: diffdir.c,v 1.34 2009/06/07 08:39:13 ray Exp $ */ /* * Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com> @@ -21,7 +21,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: diffdir.c,v 1.33 2009/06/06 15:37:28 ray Exp $"; +static const char rcsid[] = "$OpenBSD: diffdir.c,v 1.34 2009/06/07 08:39:13 ray Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -228,7 +228,7 @@ slurpdir(char *path, char **bufp, int enoentok) break; cp += dp->d_reclen; } - dirlist = xmalloc(sizeof(*dirlist) * (entries + 1)); + dirlist = xcalloc(sizeof(*dirlist), entries + 1); for (entries = 0, cp = buf; cp < ebuf; ) { dp = (struct dirent *)cp; if (dp->d_fileno != 0 && !excluded(dp->d_name)) { diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c index 74b6a72b066..95ea5089dca 100644 --- a/usr.bin/diff/diffreg.c +++ b/usr.bin/diff/diffreg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diffreg.c,v 1.71 2009/06/06 15:00:27 ray Exp $ */ +/* $OpenBSD: diffreg.c,v 1.72 2009/06/07 08:39:13 ray Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. @@ -65,7 +65,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: diffreg.c,v 1.71 2009/06/06 15:00:27 ray Exp $"; +static const char rcsid[] = "$OpenBSD: diffreg.c,v 1.72 2009/06/07 08:39:13 ray Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -289,10 +289,8 @@ u_char cup2low[256] = { }; int -diffreg(char *ofile1, char *ofile2, int flags) +diffreg(char *file1, char *file2, int flags) { - char *file1 = ofile1; - char *file2 = ofile2; FILE *f1, *f2; int i, rval, ostdout = -1; pid_t pid = -1; @@ -411,6 +409,7 @@ diffreg(char *ofile1, char *ofile2, int flags) } prepare(0, f1, stb1.st_size, flags); prepare(1, f2, stb2.st_size, flags); + prune(); sort(sfile[0], slen[0]); sort(sfile[1], slen[1]); @@ -423,10 +422,10 @@ diffreg(char *ofile1, char *ofile2, int flags) unsort(sfile[0], slen[0], class); class = xrealloc(class, slen[0] + 2, sizeof(*class)); - klist = xmalloc((slen[0] + 2) * sizeof(*klist)); + klist = xcalloc(slen[0] + 2, sizeof(*klist)); clen = 0; clistlen = 100; - clist = xmalloc(clistlen * sizeof(*clist)); + clist = xcalloc(clistlen, sizeof(*clist)); i = stone(class, slen[0], member, klist, flags); xfree(member); xfree(class); @@ -463,10 +462,6 @@ closem: fclose(f1); if (f2 != NULL) fclose(f2); - if (file1 != ofile1) - xfree(file1); - if (file2 != ofile2) - xfree(file2); return (rval); } @@ -514,7 +509,7 @@ opentemp(const char *file) if ((tempdir = getenv("TMPDIR")) == NULL) tempdir = _PATH_TMP; - + if (strlcpy(tempfile, tempdir, sizeof(tempfile)) >= sizeof(tempfile) || strlcat(tempfile, "/diff.XXXXXXXX", sizeof(tempfile)) >= sizeof(tempfile)) { @@ -564,7 +559,7 @@ prepare(int i, FILE *fd, off_t filesize, int flags) if (sz < 100) sz = 100; - p = xmalloc((sz + 3) * sizeof(*p)); + p = xcalloc(sz + 3, sizeof(*p)); for (j = 0; (h = readhash(fd, flags));) { if (j == sz) { sz = sz * 3 / 2; @@ -885,7 +880,7 @@ unsort(struct line *f, int l, int *b) { int *a, i; - a = xmalloc((l + 1) * sizeof(*a)); + a = xcalloc(l + 1, sizeof(*a)); for (i = 1; i <= l; i++) a[f[i].serial] = f[i].value; for (i = 1; i <= l; i++) @@ -913,7 +908,7 @@ output(char *file1, FILE *f1, char *file2, FILE *f2, int flags) m = len[0]; J[0] = 0; J[m + 1] = len[1] + 1; - if (format != D_EDIT) { + if (diff_format != D_EDIT) { for (i0 = 1; i0 <= m; i0 = i1 + 1) { while (i0 <= m && J[i0] == J[i0 - 1] + 1) i0++; @@ -940,7 +935,7 @@ output(char *file1, FILE *f1, char *file2, FILE *f2, int flags) } if (m == 0) change(file1, f1, file2, f2, 1, 0, 1, len[1], &flags); - if (format == D_IFDEF) { + if (diff_format == D_IFDEF) { for (;;) { #define c i0 if ((c = getc(f1)) == EOF) @@ -950,9 +945,9 @@ output(char *file1, FILE *f1, char *file2, FILE *f2, int flags) #undef c } if (anychange != 0) { - if (format == D_CONTEXT) + if (diff_format == D_CONTEXT) dump_context_vec(f1, f2, flags); - else if (format == D_UNIFIED) + else if (diff_format == D_UNIFIED) dump_unified_vec(f1, f2, flags); } } @@ -1016,7 +1011,7 @@ change(char *file1, FILE *f1, char *file2, FILE *f2, int a, int b, int c, int d, int i; restart: - if (format != D_IFDEF && a > b && c > d) + if (diff_format != D_IFDEF && a > b && c > d) return; if (ignore_pats != NULL) { char *line; @@ -1048,7 +1043,7 @@ proceed: printf("%s %s %s\n", diffargs, file1, file2); *pflags &= ~D_HEADER; } - if (format == D_CONTEXT || format == D_UNIFIED) { + if (diff_format == D_CONTEXT || diff_format == D_UNIFIED) { /* * Allocate change records as needed. */ @@ -1066,13 +1061,13 @@ proceed: */ print_header(file1, file2); anychange = 1; - } else if (a > context_vec_ptr->b + (2 * context) + 1 && - c > context_vec_ptr->d + (2 * context) + 1) { + } else if (a > context_vec_ptr->b + (2 * diff_context) + 1 && + c > context_vec_ptr->d + (2 * diff_context) + 1) { /* - * If this change is more than 'context' lines from the + * If this change is more than 'diff_context' lines from the * previous change, dump the record and reset it. */ - if (format == D_CONTEXT) + if (diff_format == D_CONTEXT) dump_context_vec(f1, f2, *pflags); else dump_unified_vec(f1, f2, *pflags); @@ -1086,15 +1081,14 @@ proceed: } if (anychange == 0) anychange = 1; - switch (format) { - + switch (diff_format) { case D_BRIEF: return; case D_NORMAL: case D_EDIT: range(a, b, ","); putchar(a > b ? 'a' : c > d ? 'd' : 'c'); - if (format == D_NORMAL) + if (diff_format == D_NORMAL) range(c, d, ","); putchar('\n'); break; @@ -1114,13 +1108,13 @@ proceed: } break; } - if (format == D_NORMAL || format == D_IFDEF) { + if (diff_format == D_NORMAL || diff_format == D_IFDEF) { fetch(ixold, a, b, f1, '<', 1, *pflags); - if (a <= b && c <= d && format == D_NORMAL) + if (a <= b && c <= d && diff_format == D_NORMAL) puts("---"); } - i = fetch(ixnew, c, d, f2, format == D_NORMAL ? '>' : '\0', 0, *pflags); - if (i != 0 && format == D_EDIT) { + i = fetch(ixnew, c, d, f2, diff_format == D_NORMAL ? '>' : '\0', 0, *pflags); + if (i != 0 && diff_format == D_EDIT) { /* * A non-zero return value for D_EDIT indicates that the * last line printed was a bare dot (".") that has been @@ -1134,7 +1128,7 @@ proceed: c += i; goto restart; } - if ((format == D_EDIT || format == D_REVERSE) && c <= d) + if ((diff_format == D_EDIT || diff_format == D_REVERSE) && c <= d) puts("."); if (inifdef) { printf("#endif /* %s */\n", ifdefname); @@ -1151,7 +1145,7 @@ fetch(long *f, int a, int b, FILE *lb, int ch, int oldfile, int flags) * When doing #ifdef's, copy down to current line * if this is the first file, so that stuff makes it to output. */ - if (format == D_IFDEF && oldfile) { + if (diff_format == D_IFDEF && oldfile) { long curpos = ftell(lb); /* print through if append (a>b), else to (nb: 0 vs 1 orig) */ nc = f[a > b ? b : a - 1] - curpos; @@ -1160,7 +1154,7 @@ fetch(long *f, int a, int b, FILE *lb, int ch, int oldfile, int flags) } if (a > b) return (0); - if (format == D_IFDEF) { + if (diff_format == D_IFDEF) { if (inifdef) { printf("#else /* %s%s */\n", oldfile == 1 ? "!" : "", ifdefname); @@ -1175,19 +1169,19 @@ fetch(long *f, int a, int b, FILE *lb, int ch, int oldfile, int flags) for (i = a; i <= b; i++) { fseek(lb, f[i - 1], SEEK_SET); nc = f[i] - f[i - 1]; - if (format != D_IFDEF && ch != '\0') { + if (diff_format != D_IFDEF && ch != '\0') { putchar(ch); - if (Tflag && (format == D_NORMAL || format == D_CONTEXT - || format == D_UNIFIED)) + if (Tflag && (diff_format == D_NORMAL || diff_format == D_CONTEXT + || diff_format == D_UNIFIED)) putchar('\t'); - else if (format != D_UNIFIED) + else if (diff_format != D_UNIFIED) putchar(' '); } col = 0; for (j = 0, lastc = '\0'; j < nc; j++, lastc = c) { if ((c = getc(lb)) == EOF) { - if (format == D_EDIT || format == D_REVERSE || - format == D_NREVERSE) + if (diff_format == D_EDIT || diff_format == D_REVERSE || + diff_format == D_NREVERSE) warnx("No newline at end of file"); else puts("\n\\ No newline at end of file"); @@ -1198,7 +1192,7 @@ fetch(long *f, int a, int b, FILE *lb, int ch, int oldfile, int flags) putchar(' '); } while (++col & 7); } else { - if (format == D_EDIT && j == 1 && c == '\n' + if (diff_format == D_EDIT && j == 1 && c == '\n' && lastc == '.') { /* * Don't print a bare "." line @@ -1320,7 +1314,6 @@ match_function(const long *f, int pos, FILE *fp) if (nc > 0) { buf[nc] = '\0'; buf[strcspn(buf, "\n")] = '\0'; - if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$') { if (begins_with(buf, "private:")) { if (!state) @@ -1334,7 +1327,7 @@ match_function(const long *f, int pos, FILE *fp) } else { strlcpy(lastbuf, buf, sizeof lastbuf); if (state) - strlcat(lastbuf, state, + strlcat(lastbuf, state, sizeof lastbuf); lastmatchline = pos; return lastbuf; @@ -1359,10 +1352,10 @@ dump_context_vec(FILE *f1, FILE *f2, int flags) return; b = d = 0; /* gcc */ - lowa = MAX(1, cvp->a - context); - upb = MIN(len[0], context_vec_ptr->b + context); - lowc = MAX(1, cvp->c - context); - upd = MIN(len[1], context_vec_ptr->d + context); + lowa = MAX(1, cvp->a - diff_context); + upb = MIN(len[0], context_vec_ptr->b + diff_context); + lowc = MAX(1, cvp->c - diff_context); + upd = MIN(len[1], context_vec_ptr->d + diff_context); printf("***************"); if ((flags & D_PROTOTYPE)) { @@ -1464,10 +1457,10 @@ dump_unified_vec(FILE *f1, FILE *f2, int flags) return; b = d = 0; /* gcc */ - lowa = MAX(1, cvp->a - context); - upb = MIN(len[0], context_vec_ptr->b + context); - lowc = MAX(1, cvp->c - context); - upd = MIN(len[1], context_vec_ptr->d + context); + lowa = MAX(1, cvp->a - diff_context); + upb = MIN(len[0], context_vec_ptr->b + diff_context); + lowc = MAX(1, cvp->c - diff_context); + upd = MIN(len[1], context_vec_ptr->d + diff_context); fputs("@@ -", stdout); uni_range(lowa, upb); @@ -1530,15 +1523,15 @@ static void print_header(const char *file1, const char *file2) { if (label[0] != NULL) - printf("%s %s\n", format == D_CONTEXT ? "***" : "---", + printf("%s %s\n", diff_format == D_CONTEXT ? "***" : "---", label[0]); else - printf("%s %s\t%s", format == D_CONTEXT ? "***" : "---", + printf("%s %s\t%s", diff_format == D_CONTEXT ? "***" : "---", file1, ctime(&stb1.st_mtime)); if (label[1] != NULL) - printf("%s %s\n", format == D_CONTEXT ? "---" : "+++", + printf("%s %s\n", diff_format == D_CONTEXT ? "---" : "+++", label[1]); else - printf("%s %s\t%s", format == D_CONTEXT ? "---" : "+++", + printf("%s %s\t%s", diff_format == D_CONTEXT ? "---" : "+++", file2, ctime(&stb2.st_mtime)); } diff --git a/usr.bin/diff/xmalloc.c b/usr.bin/diff/xmalloc.c index 125a6deea3b..b5340a9fa60 100644 --- a/usr.bin/diff/xmalloc.c +++ b/usr.bin/diff/xmalloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xmalloc.c,v 1.1 2007/05/29 18:24:56 ray Exp $ */ +/* $OpenBSD: xmalloc.c,v 1.2 2009/06/07 08:39:13 ray Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland @@ -36,6 +36,22 @@ xmalloc(size_t size) } void * +xcalloc(size_t nmemb, size_t size) +{ + void *ptr; + + if (size == 0 || nmemb == 0) + errx(1, "xcalloc: zero size"); + if (SIZE_MAX / nmemb < size) + errx(1, "xcalloc: nmemb * size > SIZE_MAX"); + ptr = calloc(nmemb, size); + if (ptr == NULL) + errx(1, "xcalloc: out of memory (allocating %lu bytes)", + (u_long)(size * nmemb)); + return ptr; +} + +void * xrealloc(void *ptr, size_t nmemb, size_t size) { void *new_ptr; @@ -43,7 +59,7 @@ xrealloc(void *ptr, size_t nmemb, size_t size) if (new_size == 0) errx(2, NULL); - if (SIZE_T_MAX / nmemb < size) + if (SIZE_MAX / nmemb < size) errx(2, NULL); if (ptr == NULL) new_ptr = malloc(new_size); diff --git a/usr.bin/diff/xmalloc.h b/usr.bin/diff/xmalloc.h index 1a17ac107d8..f348ba23c33 100644 --- a/usr.bin/diff/xmalloc.h +++ b/usr.bin/diff/xmalloc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: xmalloc.h,v 1.1 2007/05/29 18:24:56 ray Exp $ */ +/* $OpenBSD: xmalloc.h,v 1.2 2009/06/07 08:39:13 ray Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> @@ -20,6 +20,7 @@ #define XMALLOC_H void *xmalloc(size_t); +void *xcalloc(size_t, size_t); void *xrealloc(void *, size_t, size_t); void xfree(void *); char *xstrdup(const char *); diff --git a/usr.bin/rcs/diff.c b/usr.bin/rcs/diff.c index 1a85f589a1b..8139c173119 100644 --- a/usr.bin/rcs/diff.c +++ b/usr.bin/rcs/diff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diff.c,v 1.25 2007/09/11 15:47:17 gilles Exp $ */ +/* $OpenBSD: diff.c,v 1.26 2009/06/07 08:39:13 ray Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. * All rights reserved. @@ -527,7 +527,7 @@ stone(int *a, int n, int *b, int *c, int flags) /* XXX move the isqrt() out of the macro to avoid multiple calls */ const u_int bound = (flags & D_MINIMAL) ? UINT_MAX : - MAX(256, (u_int)isqrt(n)); + MAX(256, isqrt(n)); k = 0; c[0] = newcand(0, 0, 0); @@ -1166,9 +1166,7 @@ match_function(const long *f, int pos, FILE *fp) nc = fread(buf, 1, nc, fp); if (nc > 0) { buf[nc] = '\0'; - buf[strcspn(buf, "\n")] = '\0'; - if (isalpha(buf[0]) || buf[0] == '_' || buf[0] == '$') { if (begins_with(buf, "private:")) { if (!state) diff --git a/usr.bin/rcs/xmalloc.c b/usr.bin/rcs/xmalloc.c index 31953559787..cb609588b81 100644 --- a/usr.bin/rcs/xmalloc.c +++ b/usr.bin/rcs/xmalloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xmalloc.c,v 1.3 2007/02/27 07:59:13 xsa Exp $ */ +/* $OpenBSD: xmalloc.c,v 1.4 2009/06/07 08:39:13 ray Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland @@ -44,8 +44,8 @@ xcalloc(size_t nmemb, size_t size) if (size == 0 || nmemb == 0) errx(1, "xcalloc: zero size"); - if (SIZE_T_MAX / nmemb < size) - errx(1, "xcalloc: nmemb * size > SIZE_T_MAX"); + if (SIZE_MAX / nmemb < size) + errx(1, "xcalloc: nmemb * size > SIZE_MAX"); ptr = calloc(nmemb, size); if (ptr == NULL) errx(1, "xcalloc: out of memory (allocating %lu bytes)", @@ -61,8 +61,8 @@ xrealloc(void *ptr, size_t nmemb, size_t size) if (new_size == 0) errx(1, "xrealloc: zero size"); - if (SIZE_T_MAX / nmemb < size) - errx(1, "xrealloc: nmemb * size > SIZE_T_MAX"); + if (SIZE_MAX / nmemb < size) + errx(1, "xrealloc: nmemb * size > SIZE_MAX"); if (ptr == NULL) new_ptr = malloc(new_size); else |