diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2006-08-07 20:55:29 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2006-08-07 20:55:29 +0000 |
commit | 830d15121e46e520e2902cc89a177b681ba56c86 (patch) | |
tree | a3f0d9108660c47d8f99ab29b20d0519e3426823 /usr.bin/rcs | |
parent | 8f3260c23b7e5caecfcb2fb4c7e9ad2740a55292 (diff) |
More strlcpy/strlcat -> snprintf/xasprintf cleanup.
OK joris@
Diffstat (limited to 'usr.bin/rcs')
-rw-r--r-- | usr.bin/rcs/co.c | 18 | ||||
-rw-r--r-- | usr.bin/rcs/diff3.c | 14 | ||||
-rw-r--r-- | usr.bin/rcs/rcs.c | 52 |
3 files changed, 45 insertions, 39 deletions
diff --git a/usr.bin/rcs/co.c b/usr.bin/rcs/co.c index b8c09691cc0..b138aed1a0d 100644 --- a/usr.bin/rcs/co.c +++ b/usr.bin/rcs/co.c @@ -1,4 +1,4 @@ -/* $OpenBSD: co.c,v 1.96 2006/08/01 05:14:17 ray Exp $ */ +/* $OpenBSD: co.c,v 1.97 2006/08/07 20:55:28 ray Exp $ */ /* * Copyright (c) 2005 Joris Vink <joris@openbsd.org> * All rights reserved. @@ -239,7 +239,7 @@ checkout_rev(RCSFILE *file, RCSNUM *frev, const char *dst, int flags, struct stat st; struct rcs_delta *rdp; struct rcs_lock *lkp; - char msg[128], *fdate; + char *fdate; time_t rcsdate, givendate; RCSNUM *rev; @@ -320,17 +320,9 @@ checkout_rev(RCSFILE *file, RCSNUM *frev, const char *dst, int flags, if (file->rf_ndelta != 0 && rdp->rd_locker != NULL) { if (strcmp(lockname, rdp->rd_locker)) { - if (strlcpy(msg, "Revision %s is already locked by %s; ", - sizeof(msg)) >= sizeof(msg)) - errx(1, "msg too long"); - - if (flags & CO_UNLOCK) { - if (strlcat(msg, "use co -r or rcs -u", - sizeof(msg)) >= sizeof(msg)) - errx(1, "msg too long"); - } - - warnx(msg, buf, rdp->rd_locker); + warnx("Revision %s is already locked by %s; %s", + buf, rdp->rd_locker, + (flags & CO_UNLOCK) ? "use co -r or rcs -u" : ""); return (-1); } } diff --git a/usr.bin/rcs/diff3.c b/usr.bin/rcs/diff3.c index cb12594a0c9..4692c6a1a76 100644 --- a/usr.bin/rcs/diff3.c +++ b/usr.bin/rcs/diff3.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diff3.c,v 1.11 2006/07/08 09:25:44 ray Exp $ */ +/* $OpenBSD: diff3.c,v 1.12 2006/08/07 20:55:28 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.11 2006/07/08 09:25:44 ray Exp $"; + "$OpenBSD: diff3.c,v 1.12 2006/08/07 20:55:28 ray Exp $"; #endif /* not lint */ #include "includes.h" @@ -389,13 +389,13 @@ diff3_internal(int argc, char **argv, const char *fmark, const char *rmark) if (argc < 5) return (-1); - if (strlcpy(f1mark, "<<<<<<< ", sizeof(f1mark)) >= sizeof(f1mark) || - strlcat(f1mark, fmark, sizeof(f1mark)) >= sizeof(f1mark)) + i = snprintf(f1mark, sizeof(f1mark), "<<<<<<< %s", fmark); + if (i < 0 || i >= sizeof(f1mark)) errx(1, "diff3_internal: string truncated"); - if (strlcpy(f3mark, ">>>>>>> ", sizeof(f3mark)) >= sizeof(f3mark) || - strlcat(f3mark, rmark, sizeof(f3mark)) >= sizeof(f3mark)) - errx(1, "diff3_internal: strlcat"); + i = snprintf(f3mark, sizeof(f3mark), ">>>>>>> %s", rmark); + if (i < 0 || i >= sizeof(f3mark)) + errx(1, "diff3_internal: string truncated"); increase(); m = readin(argv[0], &d13); diff --git a/usr.bin/rcs/rcs.c b/usr.bin/rcs/rcs.c index 7817bdb8851..c968e777b10 100644 --- a/usr.bin/rcs/rcs.c +++ b/usr.bin/rcs/rcs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rcs.c,v 1.30 2006/08/04 06:13:54 ray Exp $ */ +/* $OpenBSD: rcs.c,v 1.31 2006/08/07 20:55:28 ray Exp $ */ /* * Copyright (c) 2004 Jean-Francois Brousseau <jfb@openbsd.org> * All rights reserved. @@ -2664,12 +2664,13 @@ rcs_expand_keywords(char *rcsfile, struct rcs_delta *rdp, BUF *bp, int mode) expbuf[0] = '\0'; if (mode & RCS_KWEXP_NAME) { - if (strlcat(expbuf, "$", sizeof(expbuf)) >= sizeof(expbuf) || - strlcat(expbuf, kwstr, sizeof(expbuf)) >= sizeof(expbuf)) - errx(1, "rcs_expand_keywords: string truncated"); - if ((mode & RCS_KWEXP_VAL) && - strlcat(expbuf, ": ", sizeof(expbuf)) >= sizeof(expbuf)) + char *tmp; + + (void)xasprintf(&tmp, "$%s%s", kwstr, + (mode & RCS_KWEXP_VAL) ? ": " : ""); + if (strlcat(expbuf, tmp, sizeof(expbuf)) >= sizeof(expbuf)) errx(1, "rcs_expand_keywords: string truncated"); + xfree(tmp); } /* @@ -2678,19 +2679,23 @@ rcs_expand_keywords(char *rcsfile, struct rcs_delta *rdp, BUF *bp, int mode) */ if (mode & RCS_KWEXP_VAL) { if (kwtype & RCS_KW_RCSFILE) { - if (!(kwtype & RCS_KW_FULLPATH)) - (void)strlcat(expbuf, basename(rcsfile), sizeof(expbuf)); - else - (void)strlcat(expbuf, rcsfile, sizeof(expbuf)); - if (strlcat(expbuf, " ", sizeof(expbuf)) >= sizeof(expbuf)) + char *tmp; + + (void)xasprintf(&tmp, "%s ", + (kwtype & RCS_KW_FULLPATH) ? rcsfile : basename(rcsfile)); + if (strlcat(expbuf, tmp, sizeof(expbuf)) >= sizeof(expbuf)) errx(1, "rcs_expand_keywords: string truncated"); + xfree(tmp); } if (kwtype & RCS_KW_REVISION) { + char *tmp; + rcsnum_tostr(rdp->rd_num, buf, sizeof(buf)); - if (strlcat(buf, " ", sizeof(buf)) >= sizeof(buf) || - strlcat(expbuf, buf, sizeof(expbuf)) >= sizeof(buf)) + (void)xasprintf(&tmp, "%s ", buf); + if (strlcat(expbuf, tmp, sizeof(expbuf)) >= sizeof(buf)) errx(1, "rcs_expand_keywords: string truncated"); + xfree(tmp); } if (kwtype & RCS_KW_DATE) { @@ -2705,15 +2710,21 @@ rcs_expand_keywords(char *rcsfile, struct rcs_delta *rdp, BUF *bp, int mode) } if (kwtype & RCS_KW_AUTHOR) { - if (strlcat(expbuf, rdp->rd_author, sizeof(expbuf)) >= sizeof(expbuf) || - strlcat(expbuf, " ", sizeof(expbuf)) >= sizeof(expbuf)) + char *tmp; + + (void)xasprintf(&tmp, "%s ", rdp->rd_author); + if (strlcat(expbuf, tmp, sizeof(expbuf)) >= sizeof(expbuf)) errx(1, "rcs_expand_keywords: string truncated"); + xfree(tmp); } if (kwtype & RCS_KW_STATE) { - if (strlcat(expbuf, rdp->rd_state, sizeof(expbuf)) >= sizeof(expbuf) || - strlcat(expbuf, " ", sizeof(expbuf)) >= sizeof(expbuf)) + char *tmp; + + (void)xasprintf(&tmp, "%s ", rdp->rd_state); + if (strlcat(expbuf, tmp, sizeof(expbuf)) >= sizeof(expbuf)) errx(1, "rcs_expand_keywords: string truncated"); + xfree(tmp); } /* order does not matter anymore below */ @@ -2722,9 +2733,12 @@ rcs_expand_keywords(char *rcsfile, struct rcs_delta *rdp, BUF *bp, int mode) errx(1, "rcs_expand_keywords: string truncated"); if (kwtype & RCS_KW_SOURCE) { - if (strlcat(expbuf, rcsfile, sizeof(expbuf)) >= sizeof(expbuf) || - strlcat(expbuf, " ", sizeof(expbuf)) >= sizeof(expbuf)) + char *tmp; + + (void)xasprintf(&tmp, "%s ", rcsfile); + if (strlcat(expbuf, tmp, sizeof(expbuf)) >= sizeof(expbuf)) errx(1, "rcs_expand_keywords: string truncated"); + xfree(tmp); } if (kwtype & RCS_KW_NAME) |