diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2006-04-05 01:38:57 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2006-04-05 01:38:57 +0000 |
commit | 0898160056a31f0981cae42f585dce85844d89b7 (patch) | |
tree | 2ab8437cd5dbf0558b5d3f90f54443694d8a7d53 | |
parent | 83701e885596de792fb8b058bf3e19ceb443a245 (diff) |
Use variable names for sizeof, remove casts in front of xmalloc,
use xcalloc and xstrdup where appropriate, and other stuff.
OK joris@
-rw-r--r-- | usr.bin/cvs/buf.c | 4 | ||||
-rw-r--r-- | usr.bin/cvs/compress.c | 5 | ||||
-rw-r--r-- | usr.bin/cvs/cvs.c | 5 | ||||
-rw-r--r-- | usr.bin/cvs/diff.c | 40 | ||||
-rw-r--r-- | usr.bin/cvs/diff3.c | 24 | ||||
-rw-r--r-- | usr.bin/cvs/entries.c | 8 | ||||
-rw-r--r-- | usr.bin/cvs/file.c | 13 | ||||
-rw-r--r-- | usr.bin/cvs/hist.c | 7 | ||||
-rw-r--r-- | usr.bin/cvs/import.c | 4 | ||||
-rw-r--r-- | usr.bin/cvs/proto.c | 6 | ||||
-rw-r--r-- | usr.bin/cvs/rcs.c | 43 | ||||
-rw-r--r-- | usr.bin/cvs/rcsnum.c | 22 | ||||
-rw-r--r-- | usr.bin/cvs/root.c | 5 | ||||
-rw-r--r-- | usr.bin/cvs/util.c | 21 | ||||
-rw-r--r-- | usr.bin/cvs/worklist.c | 5 | ||||
-rw-r--r-- | usr.bin/rcs/ci.c | 18 |
16 files changed, 104 insertions, 126 deletions
diff --git a/usr.bin/cvs/buf.c b/usr.bin/cvs/buf.c index c2e0a98a6cb..f331d5e312c 100644 --- a/usr.bin/cvs/buf.c +++ b/usr.bin/cvs/buf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buf.c,v 1.41 2006/03/28 02:13:44 ray Exp $ */ +/* $OpenBSD: buf.c,v 1.42 2006/04/05 01:38:55 ray Exp $ */ /* * Copyright (c) 2003 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -61,7 +61,7 @@ cvs_buf_alloc(size_t len, u_int flags) { BUF *b; - b = (BUF *)xmalloc(sizeof(*b)); + b = xmalloc(sizeof(*b)); /* Postpone creation of zero-sized buffers */ if (len > 0) { b->cb_buf = xmalloc(len); diff --git a/usr.bin/cvs/compress.c b/usr.bin/cvs/compress.c index aafa862c32b..a8f9ad35530 100644 --- a/usr.bin/cvs/compress.c +++ b/usr.bin/cvs/compress.c @@ -1,4 +1,4 @@ -/* $OpenBSD: compress.c,v 1.1 2006/01/03 17:04:53 xsa Exp $ */ +/* $OpenBSD: compress.c,v 1.2 2006/04/05 01:38:55 ray Exp $ */ /* * Copyright (c) 2005 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -55,8 +55,7 @@ cvs_zlib_newctx(int level) fatal("invalid compression level %d (must be between 0 and 9)", level); - ctx = (CVSZCTX *)xmalloc(sizeof(*ctx)); - memset(ctx, 0, sizeof(*ctx)); + ctx = xcalloc(1, sizeof(*ctx)); ctx->z_level = level; diff --git a/usr.bin/cvs/cvs.c b/usr.bin/cvs/cvs.c index 8aca8a8b68f..71c4c40ba4d 100644 --- a/usr.bin/cvs/cvs.c +++ b/usr.bin/cvs/cvs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cvs.c,v 1.95 2006/03/15 18:24:50 deraadt Exp $ */ +/* $OpenBSD: cvs.c,v 1.96 2006/04/05 01:38:55 ray Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -447,8 +447,7 @@ cvs_var_set(const char *var, const char *val) valcp = xstrdup(val); if (vp == NULL) { - vp = (struct cvs_var *)xmalloc(sizeof(*vp)); - memset(vp, 0, sizeof(*vp)); + vp = xcalloc(1, sizeof(*vp)); vp->cv_name = xstrdup(var); TAILQ_INSERT_TAIL(&cvs_variables, vp, cv_link); diff --git a/usr.bin/cvs/diff.c b/usr.bin/cvs/diff.c index 37ed4f0a481..caeaff903bc 100644 --- a/usr.bin/cvs/diff.c +++ b/usr.bin/cvs/diff.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diff.c,v 1.86 2006/04/01 20:11:25 joris Exp $ */ +/* $OpenBSD: diff.c,v 1.87 2006/04/05 01:38:55 ray Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. * All rights reserved. @@ -344,7 +344,7 @@ cvs_diff_init(struct cvs_cmd *cmd, int argc, char **argv, int *arg) { int ch; - dap = (struct diff_arg *)xmalloc(sizeof(*dap)); + dap = xmalloc(sizeof(*dap)); dap->date1 = dap->date2 = dap->rev1 = dap->rev2 = NULL; strlcpy(diffargs, argv[0], sizeof(diffargs)); @@ -715,18 +715,18 @@ cvs_diffreg(const char *file1, const char *file2, BUF *out) member = (int *)file[1]; equiv(sfile[0], slen[0], sfile[1], slen[1], member); - tmp = xrealloc(member, slen[1] + 2, sizeof(int)); - member = (int *)tmp; + tmp = xrealloc(member, slen[1] + 2, sizeof(*member)); + member = tmp; class = (int *)file[0]; unsort(sfile[0], slen[0], class); - tmp = xrealloc(class, slen[0] + 2, sizeof(int)); - class = (int *)tmp; + tmp = xrealloc(class, slen[0] + 2, sizeof(*class)); + class = tmp; - klist = xcalloc(slen[0] + 2, sizeof(int)); + klist = xcalloc(slen[0] + 2, sizeof(*klist)); clen = 0; clistlen = 100; - clist = xcalloc(clistlen, sizeof(cand)); + clist = xcalloc(clistlen, sizeof(*clist)); if ((i = stone(class, slen[0], member, klist)) < 0) goto closem; @@ -734,17 +734,17 @@ cvs_diffreg(const char *file1, const char *file2, BUF *out) xfree(member); xfree(class); - tmp = xrealloc(J, diff_len[0] + 2, sizeof(int)); - J = (int *)tmp; + tmp = xrealloc(J, diff_len[0] + 2, sizeof(*J)); + J = tmp; unravel(klist[i]); xfree(clist); xfree(klist); - tmp = xrealloc(ixold, diff_len[0] + 2, sizeof(long)); - ixold = (long *)tmp; + tmp = xrealloc(ixold, diff_len[0] + 2, sizeof(*ixold)); + ixold = tmp; - tmp = xrealloc(ixnew, diff_len[1] + 2, sizeof(long)); - ixnew = (long *)tmp; + tmp = xrealloc(ixnew, diff_len[1] + 2, sizeof(*ixnew)); + ixnew = tmp; check(f1, f2); output(f1, f2); @@ -803,12 +803,12 @@ prepare(int i, FILE *fd, off_t filesize) if (sz < 100) sz = 100; - p = (struct line *)xcalloc(sz + 3, sizeof(struct line)); + p = xcalloc(sz + 3, sizeof(*p)); for (j = 0; (h = readhash(fd));) { if (j == (int)sz) { sz = sz * 3 / 2; - tmp = xrealloc(p, sz + 3, sizeof(struct line)); - p = (struct line *)tmp; + tmp = xrealloc(p, sz + 3, sizeof(*p)); + p = tmp; } p[++j].value = h; } @@ -947,7 +947,7 @@ newcand(int x, int y, int pred) if (clen == clistlen) { newclistlen = clistlen * 11 / 10; - tmp = xrealloc(clist, newclistlen, sizeof(cand)); + tmp = xrealloc(clist, newclistlen, sizeof(*clist)); clist = tmp; clistlen = newclistlen; } @@ -1137,7 +1137,7 @@ unsort(struct line *f, int l, int *b) { int *a, i; - a = (int *)xcalloc(l + 1, sizeof(int)); + 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++) @@ -1289,7 +1289,7 @@ proceed: ptrdiff_t offset = context_vec_ptr - context_vec_start; max_context <<= 1; tmp = xrealloc(context_vec_start, max_context, - sizeof(struct context_vec)); + sizeof(*context_vec_start)); context_vec_start = tmp; context_vec_end = context_vec_start + max_context; context_vec_ptr = context_vec_start + offset; diff --git a/usr.bin/cvs/diff3.c b/usr.bin/cvs/diff3.c index 9a3fe391f03..1e40dbd9ca1 100644 --- a/usr.bin/cvs/diff3.c +++ b/usr.bin/cvs/diff3.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diff3.c,v 1.21 2006/03/28 02:13:44 ray Exp $ */ +/* $OpenBSD: diff3.c,v 1.22 2006/04/05 01:38:55 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.21 2006/03/28 02:13:44 ray Exp $"; + "$OpenBSD: diff3.c,v 1.22 2006/04/05 01:38:55 ray Exp $"; #endif /* not lint */ #include "includes.h" @@ -485,10 +485,12 @@ getline(FILE *b, size_t *n) if (cp[len - 1] != '\n') len++; if (len + 1 > bufsize) { + char *newbuf; do { bufsize += 1024; } while (len + 1 > bufsize); - buf = xrealloc(buf, 1, bufsize); + newbuf = xrealloc(buf, 1, bufsize); + buf = newbuf; } memcpy(buf, cp, len - 1); buf[len - 1] = '\n'; @@ -788,17 +790,17 @@ increase(void) newsz = szchanges == 0 ? 64 : 2 * szchanges; incr = newsz - szchanges; - p = xrealloc(d13, newsz, sizeof(struct diff)); - memset(p + szchanges, 0, incr * sizeof(struct diff)); + p = xrealloc(d13, newsz, sizeof(*d13)); + memset(p + szchanges, 0, incr * sizeof(*d13)); d13 = p; - p = xrealloc(d23, newsz, sizeof(struct diff)); - memset(p + szchanges, 0, incr * sizeof(struct diff)); + p = xrealloc(d23, newsz, sizeof(*d23)); + memset(p + szchanges, 0, incr * sizeof(*d23)); d23 = p; - p = xrealloc(de, newsz, sizeof(struct diff)); - memset(p + szchanges, 0, incr * sizeof(struct diff)); + p = xrealloc(de, newsz, sizeof(*de)); + memset(p + szchanges, 0, incr * sizeof(*de)); de = p; - q = xrealloc(overlap, newsz, sizeof(char)); - memset(q + szchanges, 0, incr * sizeof(char)); + q = xrealloc(overlap, newsz, sizeof(*overlap)); + memset(q + szchanges, 0, incr * sizeof(*overlap)); overlap = q; szchanges = newsz; } diff --git a/usr.bin/cvs/entries.c b/usr.bin/cvs/entries.c index 50527233645..7219dc7befd 100644 --- a/usr.bin/cvs/entries.c +++ b/usr.bin/cvs/entries.c @@ -1,4 +1,4 @@ -/* $OpenBSD: entries.c,v 1.54 2006/01/02 08:11:56 xsa Exp $ */ +/* $OpenBSD: entries.c,v 1.55 2006/04/05 01:38:55 ray Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -105,8 +105,7 @@ cvs_ent_open(const char *dir, int flags) return (NULL); } - ep = (CVSENTRIES *)xmalloc(sizeof(CVSENTRIES)); - memset(ep, 0, sizeof(*ep)); + ep = xcalloc(1, sizeof(*ep)); ep->cef_path = xstrdup(entpath); ep->cef_bpath = xstrdup(bpath); @@ -380,8 +379,7 @@ cvs_ent_parse(const char *entry) return (NULL); } - ent = (struct cvs_ent *)xmalloc(sizeof(*ent)); - memset(ent, 0, sizeof(*ent)); + ent = xcalloc(1, sizeof(*ent)); ent->ce_buf = buf; if (*fields[0] == '\0') diff --git a/usr.bin/cvs/file.c b/usr.bin/cvs/file.c index 807d139b774..c2248ecdb91 100644 --- a/usr.bin/cvs/file.c +++ b/usr.bin/cvs/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.135 2006/04/02 02:02:27 joris Exp $ */ +/* $OpenBSD: file.c,v 1.136 2006/04/05 01:38:55 ray Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -162,7 +162,7 @@ cvs_file_ignore(const char *pat) char *cp; struct cvs_ignpat *ip; - ip = (struct cvs_ignpat *)xmalloc(sizeof(*ip)); + ip = xmalloc(sizeof(*ip)); strlcpy(ip->ip_pat, pat, sizeof(ip->ip_pat)); /* check if we will need globbing for that pattern */ @@ -1043,11 +1043,7 @@ cvs_file_sort(struct cvs_flist *flp, u_int nfiles) size_t nb; CVSFILE *cf, **cfvec; - cfvec = (CVSFILE **)calloc((size_t)nfiles, sizeof(CVSFILE *)); - if (cfvec == NULL) { - cvs_log(LP_ERRNO, "failed to allocate sorting vector"); - return (-1); - } + cfvec = xcalloc((size_t)nfiles, sizeof(*cfvec)); i = 0; SIMPLEQ_FOREACH(cf, flp, cf_list) { @@ -1103,8 +1099,7 @@ cvs_file_alloc(const char *path, u_int type) CVSFILE *cfp; char *p; - cfp = (CVSFILE *)xmalloc(sizeof(*cfp)); - memset(cfp, 0, sizeof(*cfp)); + cfp = xcalloc(1, sizeof(*cfp)); cfp->cf_type = type; cfp->cf_cvstat = CVS_FST_UNKNOWN; diff --git a/usr.bin/cvs/hist.c b/usr.bin/cvs/hist.c index 1bf36d3f050..93dbf1fe5be 100644 --- a/usr.bin/cvs/hist.c +++ b/usr.bin/cvs/hist.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hist.c,v 1.13 2006/01/02 08:11:56 xsa Exp $ */ +/* $OpenBSD: hist.c,v 1.14 2006/04/05 01:38:55 ray Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -48,10 +48,9 @@ cvs_hist_open(const char *path) { CVSHIST *histp; - histp = (CVSHIST *)xmalloc(sizeof(*histp)); - memset(histp, 0, sizeof(*histp)); + histp = xcalloc(1, sizeof(*histp)); - histp->chf_buf = (char *)xmalloc((size_t)CVS_HIST_BUFSIZE); + histp->chf_buf = xmalloc((size_t)CVS_HIST_BUFSIZE); histp->chf_blen = CVS_HIST_BUFSIZE; histp->chf_off = 0; diff --git a/usr.bin/cvs/import.c b/usr.bin/cvs/import.c index 12ccf5e3b35..c364eaa5920 100644 --- a/usr.bin/cvs/import.c +++ b/usr.bin/cvs/import.c @@ -1,4 +1,4 @@ -/* $OpenBSD: import.c,v 1.41 2006/04/01 00:56:54 joris Exp $ */ +/* $OpenBSD: import.c,v 1.42 2006/04/05 01:38:55 ray Exp $ */ /* * Copyright (c) 2004 Joris Vink <joris@openbsd.org> * All rights reserved. @@ -333,7 +333,7 @@ cvs_import_local(CVSFILE *cf, void *arg) * Put the branch revision on the branches list for the first revision. */ rdp = rcs_findrev(rf, rev); - brp = (struct rcs_branch *)xmalloc(sizeof(*brp)); + brp = xmalloc(sizeof(*brp)); brp->rb_num = rcsnum_alloc(); rcsnum_cpy(brev, brp->rb_num, 0); TAILQ_INSERT_TAIL(&(rdp->rd_branches), brp, rb_list); diff --git a/usr.bin/cvs/proto.c b/usr.bin/cvs/proto.c index f7cab44192e..885c7afbb2c 100644 --- a/usr.bin/cvs/proto.c +++ b/usr.bin/cvs/proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: proto.c,v 1.93 2006/04/02 02:01:40 joris Exp $ */ +/* $OpenBSD: proto.c,v 1.94 2006/04/05 01:38:55 ray Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -404,7 +404,7 @@ cvs_req_getvalid(void) cvs_buf_putc(buf, '\0'); len = cvs_buf_len(buf); - vrstr = (char *)xmalloc(len); + vrstr = xmalloc(len); cvs_buf_copy(buf, (size_t)0, vrstr, len); cvs_buf_free(buf); @@ -474,7 +474,7 @@ cvs_resp_getvalid(void) cvs_buf_putc(buf, '\0'); len = cvs_buf_len(buf); - vrstr = (char *)xmalloc(len); + vrstr = xmalloc(len); cvs_buf_copy(buf, (size_t)0, vrstr, len); cvs_buf_free(buf); diff --git a/usr.bin/cvs/rcs.c b/usr.bin/cvs/rcs.c index ffa175561c6..90497032d26 100644 --- a/usr.bin/cvs/rcs.c +++ b/usr.bin/cvs/rcs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcs.c,v 1.160 2006/04/02 20:57:53 joris Exp $ */ +/* $OpenBSD: rcs.c,v 1.161 2006/04/05 01:38:55 ray Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -301,8 +301,7 @@ rcs_open(const char *path, int flags, ...) return (NULL); } - rfp = (RCSFILE *)xmalloc(sizeof(*rfp)); - memset(rfp, 0, sizeof(*rfp)); + rfp = xcalloc(1, sizeof(*rfp)); rfp->rf_path = xstrdup(path); rfp->rf_flags = flags | RCS_SLOCK | RCS_SYNCED; @@ -701,7 +700,7 @@ rcs_access_add(RCSFILE *file, const char *login) } } - ap = (struct rcs_access *)xmalloc(sizeof(*ap)); + ap = xmalloc(sizeof(*ap)); ap->ra_name = xstrdup(login); TAILQ_INSERT_TAIL(&(file->rf_access), ap, ra_list); @@ -765,7 +764,7 @@ rcs_sym_add(RCSFILE *rfp, const char *sym, RCSNUM *snum) } } - symp = (struct rcs_sym *)xmalloc(sizeof(*symp)); + symp = xmalloc(sizeof(*symp)); symp->rs_name = xstrdup(sym); symp->rs_num = rcsnum_alloc(); rcsnum_cpy(snum, symp->rs_num, 0); @@ -929,7 +928,7 @@ rcs_lock_add(RCSFILE *file, const char *user, RCSNUM *rev) } } - lkp = (struct rcs_lock *)xmalloc(sizeof(*lkp)); + lkp = xmalloc(sizeof(*lkp)); lkp->rl_name = xstrdup(user); lkp->rl_num = rcsnum_alloc(); rcsnum_cpy(rev, lkp->rl_num, 0); @@ -1340,8 +1339,7 @@ rcs_rev_add(RCSFILE *rf, RCSNUM *rev, const char *msg, time_t date, if ((pw = getpwuid(getuid())) == NULL) fatal("getpwuid failed"); - rdp = (struct rcs_delta *)xmalloc(sizeof(*rdp)); - memset(rdp, 0, sizeof(*rdp)); + rdp = xcalloc(1, sizeof(*rdp)); TAILQ_INIT(&(rdp->rd_branches)); @@ -1698,8 +1696,7 @@ rcs_parse_init(RCSFILE *rfp) if (rfp->rf_flags & RCS_PARSED) return (0); - pdp = (struct rcs_pdata *)xmalloc(sizeof(*pdp)); - memset(pdp, 0, sizeof(*pdp)); + pdp = xcalloc(1, sizeof(*pdp)); pdp->rp_lines = 0; pdp->rp_pttype = RCS_TOK_ERR; @@ -1707,7 +1704,7 @@ rcs_parse_init(RCSFILE *rfp) if ((pdp->rp_file = fopen(rfp->rf_path, "r")) == NULL) fatal("fopen: `%s': %s", rfp->rf_path, strerror(errno)); - pdp->rp_buf = (char *)xmalloc((size_t)RCS_BUFSIZE); + pdp->rp_buf = xmalloc((size_t)RCS_BUFSIZE); pdp->rp_blen = RCS_BUFSIZE; pdp->rp_bufend = pdp->rp_buf + pdp->rp_blen - 1; @@ -1856,8 +1853,7 @@ rcs_parse_delta(RCSFILE *rfp) struct rcs_delta *rdp; struct rcs_key *rk; - rdp = (struct rcs_delta *)xmalloc(sizeof(*rdp)); - memset(rdp, 0, sizeof(*rdp)); + rdp = xcalloc(1, sizeof(*rdp)); rdp->rd_num = rcsnum_alloc(); rdp->rd_next = rcsnum_alloc(); @@ -2086,7 +2082,7 @@ rcs_parse_deltatext(RCSFILE *rfp) return (-1); } - rdp->rd_text = (u_char *)xmalloc(RCS_TOKLEN(rfp) + 1); + rdp->rd_text = xmalloc(RCS_TOKLEN(rfp) + 1); strlcpy(rdp->rd_text, RCS_TOKSTR(rfp), (RCS_TOKLEN(rfp) + 1)); rdp->rd_tlen = RCS_TOKLEN(rfp); @@ -2143,7 +2139,7 @@ rcs_parse_symbols(RCSFILE *rfp) return (-1); } - symp = (struct rcs_sym *)xmalloc(sizeof(*symp)); + symp = xmalloc(sizeof(*symp)); symp->rs_name = xstrdup(RCS_TOKSTR(rfp)); symp->rs_num = rcsnum_alloc(); @@ -2208,7 +2204,7 @@ rcs_parse_locks(RCSFILE *rfp) return (-1); } - lkp = (struct rcs_lock *)xmalloc(sizeof(*lkp)); + lkp = xmalloc(sizeof(*lkp)); lkp->rl_name = xstrdup(RCS_TOKSTR(rfp)); lkp->rl_num = rcsnum_alloc(); @@ -2290,7 +2286,7 @@ rcs_parse_branches(RCSFILE *rfp, struct rcs_delta *rdp) return (-1); } - brp = (struct rcs_branch *)xmalloc(sizeof(*brp)); + brp = xmalloc(sizeof(*brp)); brp->rb_num = rcsnum_parse(RCS_TOKSTR(rfp)); if (brp->rb_num == NULL) { xfree(brp); @@ -2507,7 +2503,7 @@ rcs_growbuf(RCSFILE *rf) struct rcs_pdata *pdp = (struct rcs_pdata *)rf->rf_pdata; tmp = xrealloc(pdp->rp_buf, 1, pdp->rp_blen + RCS_BUFEXTSIZE); - pdp->rp_buf = (char *)tmp; + pdp->rp_buf = tmp; pdp->rp_blen += RCS_BUFEXTSIZE; pdp->rp_bufend = pdp->rp_buf + pdp->rp_blen - 1; } @@ -2708,12 +2704,14 @@ rcs_expand_keywords(char *rcsfile, struct rcs_delta *rdp, char *data, strlcat(expbuf, "$", sizeof(expbuf)); sizdiff = strlen(expbuf) - (end - start); - tbuf = xmalloc(strlen(end) + 1); - strlcpy(tbuf, end, strlen(end) + 1); + tbuf = xstrdup(end); /* only realloc if we have to */ if (sizdiff > 0) { + char *newdata; + len += sizdiff; - data = xrealloc(data, 1, len); + newdata = xrealloc(data, 1, len); + data = newdata; /* * ensure string pointers are not invalidated * after realloc() @@ -2754,7 +2752,8 @@ rcs_deltatext_set(RCSFILE *rfp, RCSNUM *rev, const char *dtext) len = strlen(dtext); if (len != 0) { - rdp->rd_text = (u_char *)xmalloc(len + 1); + /* XXX - use xstrdup() if rd_text changes to char *. */ + rdp->rd_text = xmalloc(len + 1); rdp->rd_tlen = len; (void)memcpy(rdp->rd_text, dtext, len + 1); } else { diff --git a/usr.bin/cvs/rcsnum.c b/usr.bin/cvs/rcsnum.c index bb84ec69788..8a6a6a6538e 100644 --- a/usr.bin/cvs/rcsnum.c +++ b/usr.bin/cvs/rcsnum.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcsnum.c,v 1.31 2006/03/30 23:06:25 joris Exp $ */ +/* $OpenBSD: rcsnum.c,v 1.32 2006/04/05 01:38:56 ray Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -45,7 +45,7 @@ rcsnum_alloc(void) { RCSNUM *rnp; - rnp = (RCSNUM *)xmalloc(sizeof(*rnp)); + rnp = xmalloc(sizeof(*rnp)); rnp->rn_len = 0; rnp->rn_id = NULL; @@ -153,10 +153,10 @@ rcsnum_cpy(const RCSNUM *nsrc, RCSNUM *ndst, u_int depth) len = depth; tmp = xrealloc(ndst->rn_id, len, sizeof(len)); - ndst->rn_id = (u_int16_t *)tmp; + ndst->rn_id = tmp; ndst->rn_len = len; /* Overflow checked in xrealloc(). */ - memcpy(ndst->rn_id, nsrc->rn_id, len * sizeof(len)); + (void)memcpy(ndst->rn_id, nsrc->rn_id, len * sizeof(len)); } /* @@ -213,7 +213,7 @@ rcsnum_aton(const char *str, char **ep, RCSNUM *nump) char *s; if (nump->rn_id == NULL) - nump->rn_id = (u_int16_t *)xmalloc(sizeof(u_int16_t)); + nump->rn_id = xmalloc(sizeof(*(nump->rn_id))); nump->rn_len = 0; nump->rn_id[0] = 0; @@ -230,8 +230,8 @@ rcsnum_aton(const char *str, char **ep, RCSNUM *nump) nump->rn_len++; tmp = xrealloc(nump->rn_id, - nump->rn_len + 1, sizeof(u_int16_t)); - nump->rn_id = (u_int16_t *)tmp; + nump->rn_len + 1, sizeof(*(nump->rn_id))); + nump->rn_id = tmp; nump->rn_id[nump->rn_len] = 0; continue; } @@ -297,8 +297,8 @@ rcsnum_aton(const char *str, char **ep, RCSNUM *nump) /* We can't have a single-digit rcs number. */ if (nump->rn_len == 0) { tmp = xrealloc(nump->rn_id, - nump->rn_len + 1, sizeof(u_int16_t)); - nump->rn_id = (u_int16_t *)tmp; + nump->rn_len + 1, sizeof(*(nump->rn_id))); + nump->rn_id = tmp; nump->rn_id[nump->rn_len + 1] = 0; nump->rn_len++; } @@ -401,8 +401,8 @@ rcsnum_setsize(RCSNUM *num, u_int len) { void *tmp; - tmp = xrealloc(num->rn_id, len, sizeof(u_int16_t)); - num->rn_id = (u_int16_t *)tmp; + tmp = xrealloc(num->rn_id, len, sizeof(*(num->rn_id))); + num->rn_id = tmp; num->rn_len = len; return (0); } diff --git a/usr.bin/cvs/root.c b/usr.bin/cvs/root.c index bfadd5d5960..b1252ed7264 100644 --- a/usr.bin/cvs/root.c +++ b/usr.bin/cvs/root.c @@ -1,4 +1,4 @@ -/* $OpenBSD: root.c,v 1.30 2006/01/25 13:31:45 xsa Exp $ */ +/* $OpenBSD: root.c,v 1.31 2006/04/05 01:38:56 ray Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -90,8 +90,7 @@ cvsroot_parse(const char *str) } } - root = (struct cvsroot *)xmalloc(sizeof(*root)); - memset(root, 0, sizeof(*root)); + root = xcalloc(1, sizeof(*root)); root->cr_ref = 1; root->cr_method = CVS_METHOD_NONE; CVS_RSTVR(root); diff --git a/usr.bin/cvs/util.c b/usr.bin/cvs/util.c index a655005d56f..71cf65c2066 100644 --- a/usr.bin/cvs/util.c +++ b/usr.bin/cvs/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.76 2006/03/29 09:16:53 ray Exp $ */ +/* $OpenBSD: util.c,v 1.77 2006/04/05 01:38:56 ray Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * Copyright (c) 2005, 2006 Joris Vink <joris@openbsd.org> @@ -380,15 +380,12 @@ cvs_makeargv(const char *line, int *argc) { int i, ret; char *argv[1024], **copy; - size_t size; ret = cvs_getargv(line, argv, 1024); if (ret == -1) return (NULL); - size = (ret + 1) * sizeof(char *); - copy = (char **)xmalloc(size); - memset(copy, 0, size); + copy = xcalloc(ret + 1, sizeof(char *)); for (i = 0; i < ret; i++) copy[i] = argv[i]; @@ -945,18 +942,18 @@ cvs_splitlines(const char *fcont) struct cvs_lines *lines; struct cvs_line *lp; - lines = (struct cvs_lines *)xmalloc(sizeof(*lines)); + lines = xmalloc(sizeof(*lines)); TAILQ_INIT(&(lines->l_lines)); lines->l_nblines = 0; lines->l_data = xstrdup(fcont); - lp = (struct cvs_line *)xmalloc(sizeof(*lp)); + lp = xmalloc(sizeof(*lp)); lp->l_line = NULL; lp->l_lineno = 0; TAILQ_INSERT_TAIL(&(lines->l_lines), lp, l_list); for (dcp = lines->l_data; *dcp != '\0';) { - lp = (struct cvs_line *)xmalloc(sizeof(*lp)); + lp = xmalloc(sizeof(*lp)); lp->l_line = dcp; lp->l_lineno = ++(lines->l_nblines); TAILQ_INSERT_TAIL(&(lines->l_lines), lp, l_list); @@ -1061,14 +1058,14 @@ cvs_strsplit(char *str, const char *sep) char *cp, *p; cp = xstrdup(str); - av = xmalloc(sizeof(struct cvs_argvector)); + av = xmalloc(sizeof(*av)); av->str = cp; - av->argv = (char **)xcalloc(i + 1, sizeof(char *)); + av->argv = xcalloc(i + 1, sizeof(*(av->argv))); while ((p = strsep(&cp, sep)) != NULL) { av->argv[i++] = p; - nargv = (char **)xrealloc((void *)av->argv, - i + 1, sizeof(char *)); + nargv = xrealloc(av->argv, + i + 1, sizeof(*(av->argv))); av->argv = nargv; } av->argv[i] = NULL; diff --git a/usr.bin/cvs/worklist.c b/usr.bin/cvs/worklist.c index f15221a047e..52564221f02 100644 --- a/usr.bin/cvs/worklist.c +++ b/usr.bin/cvs/worklist.c @@ -1,4 +1,4 @@ -/* $OpenBSD: worklist.c,v 1.4 2006/03/15 13:32:41 niallo Exp $ */ +/* $OpenBSD: worklist.c,v 1.5 2006/04/05 01:38:56 ray Exp $ */ /* * Copyright (c) 2006 Joris Vink <joris@openbsd.org> * All rights reserved. @@ -40,8 +40,7 @@ cvs_worklist_add(const char *path, struct cvs_wklhead *worklist) struct cvs_worklist *wkl; sigset_t old, new; - wkl = (struct cvs_worklist *)xmalloc(sizeof(*wkl)); - memset(wkl, 0, sizeof(*wkl)); + wkl = xcalloc(1, sizeof(*wkl)); len = strlcpy(wkl->wkl_path, path, sizeof(wkl->wkl_path)); if (len >= sizeof(wkl->wkl_path)) diff --git a/usr.bin/rcs/ci.c b/usr.bin/rcs/ci.c index 451adcfabde..7acabc4b24d 100644 --- a/usr.bin/rcs/ci.c +++ b/usr.bin/rcs/ci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ci.c,v 1.134 2006/04/01 13:57:48 niallo Exp $ */ +/* $OpenBSD: ci.c,v 1.135 2006/04/05 01:38:56 ray Exp $ */ /* * Copyright (c) 2005, 2006 Niall O'Higgins <niallo@openbsd.org> * All rights reserved. @@ -1014,12 +1014,8 @@ checkin_parsekeyword(char *keystring, RCSNUM **rev, time_t *date, if ((*rev = rcsnum_parse(tokens[2])) == NULL) fatal("could not parse rcsnum"); } - len = strlen(tokens[5]) + 1; - *author = xmalloc(len); - strlcpy(*author, tokens[5], len); - len = strlen(tokens[6]) + 1; - *state = xmalloc(len); - strlcpy(*state, tokens[6], len); + *author = xstrdup(tokens[5]); + *author = xstrdup(tokens[6]); len = strlen(tokens[3]) + strlen(tokens[4]) + 2; datestring = xmalloc(len); strlcpy(datestring, tokens[3], len); @@ -1037,9 +1033,7 @@ checkin_parsekeyword(char *keystring, RCSNUM **rev, time_t *date, } if (*author != NULL) xfree(*author); - len = strlen(tokens[1]) + 1; - *author = xmalloc(len); - strlcpy(*author, tokens[1], len); + *author = xstrdup(tokens[1]); break; case KW_TYPE_DATE: for ((p = strtok(keystring, " ")); p; @@ -1064,9 +1058,7 @@ checkin_parsekeyword(char *keystring, RCSNUM **rev, time_t *date, } if (*state != NULL) xfree(*state); - len = strlen(tokens[1]) + 1; - *state = xmalloc(len); - strlcpy(*state, tokens[1], len); + *state = xstrdup(tokens[1]); break; case KW_TYPE_REVISION: /* only parse revision if one is not already set */ |