From 82e75344d0b009e3f1b7e8dec520dfd3e0c15f2a Mon Sep 17 00:00:00 2001 From: eric Date: Wed, 31 Mar 2021 19:09:19 +0000 Subject: [PATCH] turn log_trace() into a macro to prevent evaluating the format string parameters when tracing is not enabled. ok millert@ --- usr.sbin/smtpd/smtpd.h | 7 ++++--- usr.sbin/smtpd/util.c | 12 +++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h index 4b5da97b44e..d36e33285e5 100644 --- a/usr.sbin/smtpd/smtpd.h +++ b/usr.sbin/smtpd/smtpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.h,v 1.663 2021/03/31 17:47:16 eric Exp $ */ +/* $OpenBSD: smtpd.h,v 1.664 2021/03/31 19:09:19 eric Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -1749,8 +1749,9 @@ int base64_encode_rfc3548(unsigned char const *, size_t, char *, size_t); void log_trace_verbose(int); -void log_trace(int, const char *, ...) - __attribute__((format (printf, 2, 3))); +void log_trace0(const char *, ...) + __attribute__((format (printf, 1, 2))); +#define log_trace(m, ...) do { if (tracing & (m)) log_trace0(__VA_ARGS__); } while (0) /* waitq.c */ int waitq_wait(void *, void (*)(void *, void *, void *), void *); diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c index 91e93678f77..9b6664b87fd 100644 --- a/usr.sbin/smtpd/util.c +++ b/usr.sbin/smtpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.152 2020/11/29 20:07:38 tb Exp $ */ +/* $OpenBSD: util.c,v 1.153 2021/03/31 19:09:19 eric Exp $ */ /* * Copyright (c) 2000,2001 Markus Friedl. All rights reserved. @@ -823,15 +823,13 @@ base64_encode_rfc3548(unsigned char const *src, size_t srclen, } void -log_trace(int mask, const char *emsg, ...) +log_trace0(const char *emsg, ...) { va_list ap; - if (tracing & mask) { - va_start(ap, emsg); - vlog(LOG_DEBUG, emsg, ap); - va_end(ap); - } + va_start(ap, emsg); + vlog(LOG_DEBUG, emsg, ap); + va_end(ap); } void -- 2.20.1