diff options
author | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2014-11-16 19:07:52 +0000 |
---|---|---|
committer | Alexander Bluhm <bluhm@cvs.openbsd.org> | 2014-11-16 19:07:52 +0000 |
commit | ea37fd90cfcaf04e682b0b1ac82c9cdc481ee9c8 (patch) | |
tree | fc235a385ba0bc7e1f5aacfe056fc580a801019d | |
parent | bd7d610a442003b4ea0595f768150b95dad9b686 (diff) |
Convert the logic in yyerror(). Instead of creating a temporary
format string, create a temporary message.
OK doug@
-rw-r--r-- | bin/chio/parse.y | 12 | ||||
-rw-r--r-- | usr.sbin/npppd/npppd/parse.y | 12 | ||||
-rw-r--r-- | usr.sbin/smtpd/parse.y | 12 | ||||
-rw-r--r-- | usr.sbin/smtpd/smtpd.h | 3 | ||||
-rw-r--r-- | usr.sbin/snmpd/parse.y | 12 | ||||
-rw-r--r-- | usr.sbin/snmpd/snmpd.h | 3 |
6 files changed, 28 insertions, 26 deletions
diff --git a/bin/chio/parse.y b/bin/chio/parse.y index 1c1e2e7bb5f..ad77520ae29 100644 --- a/bin/chio/parse.y +++ b/bin/chio/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.18 2014/11/14 03:20:36 doug Exp $ */ +/* $OpenBSD: parse.y,v 1.19 2014/11/16 19:07:50 bluhm Exp $ */ /* * Copyright (c) 2006 Bob Beck <beck@openbsd.org> @@ -139,15 +139,15 @@ int yyerror(const char *fmt, ...) { va_list ap; - char *nfmt; + char *msg; file->errors++; va_start(ap, fmt); - if (asprintf(&nfmt, "%s:%d: %s", file->name, yylval.lineno, fmt) == -1) - err(1, "yyerror asprintf"); - err(1, nfmt, ap); + if (vasprintf(&msg, fmt, ap) == -1) + err(1, "yyerror vasprintf"); va_end(ap); - free(nfmt); + err(1, "%s:%d: %s", file->name, yylval.lineno, msg); + free(msg); return (0); } diff --git a/usr.sbin/npppd/npppd/parse.y b/usr.sbin/npppd/npppd/parse.y index bff6ee7511b..f075b9c6c54 100644 --- a/usr.sbin/npppd/npppd/parse.y +++ b/usr.sbin/npppd/npppd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.13 2014/11/14 03:20:37 doug Exp $ */ +/* $OpenBSD: parse.y,v 1.14 2014/11/16 19:07:50 bluhm Exp $ */ /* * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -953,15 +953,15 @@ int yyerror(const char *fmt, ...) { va_list ap; - char *nfmt; + char *msg; file->errors++; va_start(ap, fmt); - if (asprintf(&nfmt, "%s:%d: %s", file->name, yylval.lineno, fmt) == -1) - fatalx("yyerror asprintf"); - vlog(LOG_CRIT, nfmt, ap); + if (vasprintf(&msg, fmt, ap) == -1) + fatalx("yyerror vasprintf"); va_end(ap); - free(nfmt); + logit(LOG_CRIT, "%s:%d: %s", file->name, yylval.lineno, msg); + free(msg); return (0); } diff --git a/usr.sbin/smtpd/parse.y b/usr.sbin/smtpd/parse.y index f514bb32004..3f9e658c97d 100644 --- a/usr.sbin/smtpd/parse.y +++ b/usr.sbin/smtpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.147 2014/11/14 03:20:37 doug Exp $ */ +/* $OpenBSD: parse.y,v 1.148 2014/11/16 19:07:50 bluhm Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -1240,15 +1240,15 @@ int yyerror(const char *fmt, ...) { va_list ap; - char *nfmt; + char *msg; file->errors++; va_start(ap, fmt); - if (asprintf(&nfmt, "%s:%d: %s", file->name, yylval.lineno, fmt) == -1) - fatalx("yyerror asprintf"); - vlog(LOG_CRIT, nfmt, ap); + if (vasprintf(&msg, fmt, ap) == -1) + fatalx("yyerror vasprintf"); va_end(ap); - free(nfmt); + logit(LOG_CRIT, "%s:%d: %s", file->name, yylval.lineno, msg); + free(msg); return (0); } diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 3377b41daec..3c1522b19e0 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.469 2014/10/15 08:09:02 gilles Exp $ */ +/* $OpenBSD: smtpd.h,v 1.470 2014/11/16 19:07:50 bluhm Exp $ */ /* * Copyright (c) 2008 Gilles Chehade <gilles@poolp.org> @@ -1174,6 +1174,7 @@ void lka_session_forward_reply(struct forward_req *, int); /* log.c */ void vlog(int, const char *, va_list); +void logit(int, const char *, ...) __attribute__((format (printf, 2, 3))); /* mda.c */ diff --git a/usr.sbin/snmpd/parse.y b/usr.sbin/snmpd/parse.y index ac3c031f461..79be9355283 100644 --- a/usr.sbin/snmpd/parse.y +++ b/usr.sbin/snmpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.33 2014/11/14 03:20:37 doug Exp $ */ +/* $OpenBSD: parse.y,v 1.34 2014/11/16 19:07:51 bluhm Exp $ */ /* * Copyright (c) 2007, 2008, 2012 Reyk Floeter <reyk@openbsd.org> @@ -573,15 +573,15 @@ int yyerror(const char *fmt, ...) { va_list ap; - char *nfmt; + char *msg; file->errors++; va_start(ap, fmt); - if (asprintf(&nfmt, "%s:%d: %s", file->name, yylval.lineno, fmt) == -1) - fatalx("yyerror asprintf"); - vlog(LOG_CRIT, nfmt, ap); + if (vasprintf(&msg, fmt, ap) == -1) + fatalx("yyerror vasprintf"); va_end(ap); - free(nfmt); + logit(LOG_CRIT, "%s:%d: %s", file->name, yylval.lineno, msg); + free(msg); return (0); } diff --git a/usr.sbin/snmpd/snmpd.h b/usr.sbin/snmpd/snmpd.h index 173d3d6ae66..77a41c0ff10 100644 --- a/usr.sbin/snmpd/snmpd.h +++ b/usr.sbin/snmpd/snmpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: snmpd.h,v 1.56 2014/08/18 13:13:42 reyk Exp $ */ +/* $OpenBSD: snmpd.h,v 1.57 2014/11/16 19:07:51 bluhm Exp $ */ /* * Copyright (c) 2007, 2008, 2012 Reyk Floeter <reyk@openbsd.org> @@ -581,6 +581,7 @@ void print_debug(const char *, ...); void print_verbose(const char *, ...); __dead void fatal(const char *); __dead void fatalx(const char *); +void logit(int, const char *, ...); void vlog(int, const char *, va_list); const char *log_in6addr(const struct in6_addr *); const char *print_host(struct sockaddr_storage *, char *, size_t); |