mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 00:14:32 +09:00
log: replace format string in LOG_ITEM() to a dummy one when analyzed by Coverity
Hopefully silence many false-positives.
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user