summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2014-11-16 19:14:35 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2014-11-16 19:14:35 +0000
commita7e47311bd78190d9f855ac61d5c6623ddef5739 (patch)
tree72b5635a8489dd87db1bd6659e6ad4540364961d /usr.bin
parentea37fd90cfcaf04e682b0b1ac82c9cdc481ee9c8 (diff)
Convert the logic in rcsparse_warnx(). Instead of creating a
temporary format string, create a temporary message. If there is not enough memory to log the error, just log this second error. The double error path gets never tested, so it should be simple. Make it work like the other places. OK doug@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/cvs/rcsparse.c17
-rw-r--r--usr.bin/rcs/rcsparse.c17
2 files changed, 18 insertions, 16 deletions
diff --git a/usr.bin/cvs/rcsparse.c b/usr.bin/cvs/rcsparse.c
index 4c73f384386..0c615eef0ce 100644
--- a/usr.bin/cvs/rcsparse.c
+++ b/usr.bin/cvs/rcsparse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsparse.c,v 1.7 2013/06/03 17:04:35 jcs Exp $ */
+/* $OpenBSD: rcsparse.c,v 1.8 2014/11/16 19:14:34 bluhm Exp $ */
/*
* Copyright (c) 2010 Tobias Stoeckmann <tobias@openbsd.org>
*
@@ -1259,15 +1259,16 @@ rcsparse_warnx(RCSFILE *rfp, char *fmt, ...)
{
struct rcs_pdata *pdp;
va_list ap;
- char *nfmt;
+ char *msg;
pdp = (struct rcs_pdata *)rfp->rf_pdata;
va_start(ap, fmt);
- if (asprintf(&nfmt, "%s:%d: %s", rfp->rf_path, pdp->rp_msglineno, fmt)
- == -1)
- nfmt = fmt;
- cvs_vlog(LP_ERR, nfmt, ap);
+ if (vasprintf(&msg, fmt, ap) == -1) {
+ cvs_log(LP_ERRNO, "vasprintf");
+ va_end(ap);
+ return;
+ }
va_end(ap);
- if (nfmt != fmt)
- free(nfmt);
+ cvs_log(LP_ERR, "%s:%d: %s", rfp->rf_path, pdp->rp_msglineno, msg);
+ free(msg);
}
diff --git a/usr.bin/rcs/rcsparse.c b/usr.bin/rcs/rcsparse.c
index 1f37e66babd..0a361847b1d 100644
--- a/usr.bin/rcs/rcsparse.c
+++ b/usr.bin/rcs/rcsparse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rcsparse.c,v 1.10 2014/10/10 08:15:25 otto Exp $ */
+/* $OpenBSD: rcsparse.c,v 1.11 2014/11/16 19:14:34 bluhm Exp $ */
/*
* Copyright (c) 2010 Tobias Stoeckmann <tobias@openbsd.org>
*
@@ -1256,15 +1256,16 @@ rcsparse_warnx(RCSFILE *rfp, char *fmt, ...)
{
struct rcs_pdata *pdp;
va_list ap;
- char *nfmt;
+ char *msg;
pdp = (struct rcs_pdata *)rfp->rf_pdata;
va_start(ap, fmt);
- if (asprintf(&nfmt, "%s:%d: %s", rfp->rf_path, pdp->rp_msglineno, fmt)
- == -1)
- nfmt = fmt;
- vwarnx(nfmt, ap);
+ if (vasprintf(&msg, fmt, ap) == -1) {
+ warn("vasprintf");
+ va_end(ap);
+ return;
+ }
va_end(ap);
- if (nfmt != fmt)
- free(nfmt);
+ warnx("%s:%d: %s", rfp->rf_path, pdp->rp_msglineno, msg);
+ free(msg);
}