]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
log: replace format string in LOG_ITEM() to a dummy one when analyzed by Coverity
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 16 Nov 2025 10:18:45 +0000 (19:18 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 17 Nov 2025 14:06:53 +0000 (23:06 +0900)
Hopefully silence many false-positives.

src/basic/log.h

index 134169c824c906afad8d78bb9c3e735cf86ca313..6bd0c2dec0740b3d71e6f8675a92fe4b9474d009 100644 (file)
@@ -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);