diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2006-03-29 09:16:54 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2006-03-29 09:16:54 +0000 |
commit | 4c12ebc9cf33799a65150ee8252ff495be853783 (patch) | |
tree | 984104ae10662e0350a751dd813ac641602757be /usr.bin | |
parent | c29b2c79b4a37d545574ebd21b44c9a92fefa31e (diff) |
Yet more lint:
- Explicitly test for -1 from read(2) and write(2).
- Change negative parameters to 0 for rcsnum_cmp(). (I think xsa@ had
a patch for this earlier.)
- Remove unused variables.
- Changed return types to void if we only return one value.
- Fix possible one-character truncation in rcs_deltatext_set().
- Use memcpy() to copy u_char arrays.
- Use ptrdiff_t to hold pointer differences.
- int -> size_t for sizeof/strlen
``looks fine'' xsa@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/cvs/rcs.c | 39 | ||||
-rw-r--r-- | usr.bin/cvs/util.c | 4 |
2 files changed, 23 insertions, 20 deletions
diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c index bca3180d550..62fc1b6b2c7 100644 --- a/usr.bin/cvs/rcs.c +++ b/usr.bin/cvs/rcs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcs.c,v 1.154 2006/03/28 07:42:56 ray Exp $ */ +/* $OpenBSD: rcs.c,v 1.155 2006/03/29 09:16:53 ray Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -251,7 +251,7 @@ static void rcs_freepdata(struct rcs_pdata *); static int rcs_gettok(RCSFILE *); static int rcs_pushtok(RCSFILE *, const char *, int); static void rcs_growbuf(RCSFILE *); -static int rcs_strprint(const u_char *, size_t, FILE *); +static void rcs_strprint(const u_char *, size_t, FILE *); static char* rcs_expand_keywords(char *, struct rcs_delta *, char *, size_t, int); @@ -412,7 +412,7 @@ rcs_write(RCSFILE *rfp) struct rcs_branch *brp; struct rcs_delta *rdp; struct rcs_lock *lkp; - ssize_t nread; + ssize_t nread, nwritten; size_t len; int fd, from_fd, to_fd; @@ -569,8 +569,13 @@ rcs_write(RCSFILE *rfp) } bp = xmalloc(MAXBSIZE); - while ((nread = read(from_fd, bp, MAXBSIZE)) > 0) { - if (write(to_fd, bp, nread) != nread) + for (;;) { + if ((nread = read(from_fd, bp, MAXBSIZE)) == 0) + break; + if (nread == -1) + goto err; + nwritten = write(to_fd, bp, (size_t)nread); + if (nwritten == -1 || nwritten != nread) goto err; } @@ -1366,7 +1371,7 @@ rcs_findrev(RCSFILE *rfp, RCSNUM *rev) */ enddelta = TAILQ_LAST(&(rfp->rf_delta), rcs_dlist); if ((enddelta == NULL) - || (rcsnum_cmp(enddelta->rd_num, rev, -1) == -1)) { + || (rcsnum_cmp(enddelta->rd_num, rev, 0) == -1)) { rcs_parse_deltas(rfp, rev); } @@ -1529,7 +1534,7 @@ rcs_parse_deltas(RCSFILE *rfp, RCSNUM *rev) ret = rcs_parse_delta(rfp); if (rev != NULL) { enddelta = TAILQ_LAST(&(rfp->rf_delta), rcs_dlist); - if (rcsnum_cmp(enddelta->rd_num, rev, -1) == 0) + if (rcsnum_cmp(enddelta->rd_num, rev, 0) == 0) break; } if (ret == 0) { @@ -2448,14 +2453,13 @@ rcs_growbuf(RCSFILE *rf) * '@' characters are escaped. Otherwise, the string can contain arbitrary * binary data. */ -static int +static void rcs_strprint(const u_char *str, size_t slen, FILE *stream) { const u_char *ap, *ep, *sp; - size_t ret; if (slen == 0) - return (0); + return; ep = str + slen - 1; @@ -2463,14 +2467,12 @@ rcs_strprint(const u_char *str, size_t slen, FILE *stream) ap = memchr(sp, '@', ep - sp); if (ap == NULL) ap = ep; - ret = fwrite(sp, sizeof(u_char), ap - sp + 1, stream); + (void)fwrite(sp, sizeof(u_char), ap - sp + 1, stream); if (*ap == '@') putc('@', stream); sp = ap + 1; } - - return (0); } /* @@ -2484,9 +2486,10 @@ static char * rcs_expand_keywords(char *rcsfile, struct rcs_delta *rdp, char *data, size_t len, int mode) { + ptrdiff_t c_offset, sizdiff, start_offset; size_t i; - int kwtype, sizdiff; - u_int j, found, start_offset, c_offset; + int kwtype; + u_int j, found; char *c, *kwstr, *start, *end, *tbuf; char expbuf[256], buf[256]; struct tm *tb; @@ -2685,9 +2688,9 @@ rcs_deltatext_set(RCSFILE *rfp, RCSNUM *rev, const char *dtext) len = strlen(dtext); if (len != 0) { - rdp->rd_text = (u_char *)xmalloc(len); - rdp->rd_tlen = len - 1; - strlcpy(rdp->rd_text, dtext, len); + rdp->rd_text = (u_char *)xmalloc(len + 1); + rdp->rd_tlen = len; + (void)memcpy(rdp->rd_text, dtext, len + 1); } else { rdp->rd_text = NULL; rdp->rd_tlen = 0; diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c index 2a5c611fee5..a655005d56f 100644 --- a/usr.bin/cvs/util.c +++ b/usr.bin/cvs/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.75 2006/03/28 07:17:17 ray Exp $ */ +/* $OpenBSD: util.c,v 1.76 2006/03/29 09:16:53 ray Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * Copyright (c) 2005, 2006 Joris Vink <joris@openbsd.org> @@ -1056,9 +1056,9 @@ struct cvs_argvector * cvs_strsplit(char *str, const char *sep) { struct cvs_argvector *av; + size_t i = 0; char **nargv; char *cp, *p; - int i = 0; cp = xstrdup(str); av = xmalloc(sizeof(struct cvs_argvector)); |