From: Yu Watanabe Date: Sun, 16 Nov 2025 10:18:45 +0000 (+0900) Subject: log: replace format string in LOG_ITEM() to a dummy one when analyzed by Coverity X-Git-Tag: v259-rc1~11^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d753c0c65821ec04a6a7487ad8be3d775651077c;p=thirdparty%2Fsystemd.git log: replace format string in LOG_ITEM() to a dummy one when analyzed by Coverity Hopefully silence many false-positives. --- diff --git a/src/basic/log.h b/src/basic/log.h index 134169c824c..6bd0c2dec07 100644 --- a/src/basic/log.h +++ b/src/basic/log.h @@ -287,18 +287,21 @@ 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__) +#ifdef __COVERITY__ +/* Coverity does not like the concatenation of multiple formats and arguments. Let's replace each format + * string with a dummy string. The validity of the formats is hopefully checked by other CIs. */ +# define LOG_ITEM(fmt, ...) "dummy", NULL, ##__VA_ARGS__ +#elif LOG_MESSAGE_VERIFICATION /* 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_ITEM(fmt, ...) "%.0d" fmt, (_log_message_dummy && printf(fmt, ##__VA_ARGS__)), ##__VA_ARGS__ -# define LOG_MESSAGE(fmt, ...) LOG_ITEM("MESSAGE=" fmt, ##__VA_ARGS__) #else # define LOG_ITEM(fmt, ...) fmt, ##__VA_ARGS__ -# define LOG_MESSAGE(fmt, ...) "MESSAGE=" fmt, ##__VA_ARGS__ #endif -#define LOG_MESSAGE_ID(id) LOG_ITEM("MESSAGE_ID=" id) +#define LOG_MESSAGE(fmt, ...) LOG_ITEM("MESSAGE=" fmt, ##__VA_ARGS__) +#define LOG_MESSAGE_ID(id) LOG_ITEM("MESSAGE_ID=" id) void log_received_signal(int level, const struct signalfd_siginfo *si);