From 011a03a3fae25f2b715f2d88bc16b4cb8f8f2da2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 11 May 2022 16:42:13 +0200 Subject: [PATCH] meson: turn on log-message-verification by default in developer builds MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit I'm not _quite_ convinced that this a good idea… I'm at least keeping it separate to make it easy to revert ;) --- meson.build | 8 +++++++- meson_options.txt | 2 +- src/basic/log.c | 4 ++++ src/basic/log.h | 7 ++++--- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/meson.build b/meson.build index 46f062d5303..7d4233ca7fa 100644 --- a/meson.build +++ b/meson.build @@ -33,7 +33,13 @@ conf.set_quoted('RELATIVE_SOURCE_PATH', relative_source_path) conf.set10('BUILD_MODE_DEVELOPER', get_option('mode') == 'developer', description : 'tailor build to development or release builds') -conf.set10('LOG_MESSAGE_VERIFICATION', get_option('log-message-verification')) +verification = get_option('log-message-verification') +if verification == 'auto' + verification = conf.get('BUILD_MODE_DEVELOPER') == 1 +else + verification = verification == 'true' +endif +conf.set10('LOG_MESSAGE_VERIFICATION', verification) want_ossfuzz = get_option('oss-fuzz') want_libfuzzer = get_option('llvm-fuzz') diff --git a/meson_options.txt b/meson_options.txt index ff59120f77d..26d1170c504 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -470,7 +470,7 @@ option('fuzz-tests', type : 'boolean', value : 'false', description : 'run the fuzzer regression tests by default (with sanitizers)') option('install-tests', type : 'boolean', value : 'false', description : 'install test executables') -option('log-message-verification', type : 'boolean', value : 'false', +option('log-message-verification', type : 'combo', choices : ['auto', 'true', 'false'], description : 'do fake printf() calls to verify format strings') option('ok-color', type : 'combo', diff --git a/src/basic/log.c b/src/basic/log.c index 12071e2ebd3..8f36c1dfadd 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -67,6 +67,10 @@ static bool prohibit_ipc = false; * use here. */ static char *log_abort_msg = NULL; +#if LOG_MESSAGE_VERIFICATION || defined(__COVERITY__) +bool _log_message_dummy = false; /* Always false */ +#endif + /* An assert to use in logging functions that does not call recursively * into our logging functions (since that might lead to a loop). */ #define assert_raw(expr) \ diff --git a/src/basic/log.h b/src/basic/log.h index 7b89c4df634..b7b0a42e494 100644 --- a/src/basic/log.h +++ b/src/basic/log.h @@ -301,9 +301,10 @@ bool log_on_console(void) _pure_; /* Helper to wrap the main message in structured logging. The macro doesn't do much, * except to provide visual grouping of the format string and its arguments. */ #if LOG_MESSAGE_VERIFICATION || defined(__COVERITY__) -/* Do a fake formatting of the message string to let the scanner verify the arguments - * against the format message. */ -# define LOG_MESSAGE(fmt, ...) "MESSAGE=%.0d" fmt, printf(fmt, ##__VA_ARGS__), ##__VA_ARGS__ +/* Do a fake formatting of the message string to let the scanner verify the arguments against the format + * message. The variable will never be set to true, but we don't tell the compiler that :) */ +extern bool _log_message_dummy; +# define LOG_MESSAGE(fmt, ...) "MESSAGE=%.0d" fmt, (_log_message_dummy && printf(fmt, ##__VA_ARGS__)), ##__VA_ARGS__ #else # define LOG_MESSAGE(fmt, ...) "MESSAGE=" fmt, ##__VA_ARGS__ #endif -- 2.47.3