MT#55283 fix side effects from double printing

Evaluating the __VA_ARGS__ twice for printing a critical error can have
side effects. Avoid these by using an intermediate buffer.

Change-Id: I8ddace6ad06f47d6827f3f3ba3c5b882cbfb0140
pull/1729/head
Richard Fuchs 2 years ago
parent 13eacc6364
commit 7235d906ff

@ -104,8 +104,10 @@ INLINE int __get_log_level(unsigned int idx) {
#define die(fmt, ...) do { \ #define die(fmt, ...) do { \
fprintf(stderr, "Fatal error: " fmt "\n", ##__VA_ARGS__); \ char *__msg = g_strdup_printf(fmt, ##__VA_ARGS__); \
ilog(LOG_CRIT, "Fatal error: " fmt, ##__VA_ARGS__); \ fprintf(stderr, "Fatal error: %s\n", __msg); \
ilog(LOG_CRIT, "Fatal error: %s", __msg); \
g_free(__msg); \
exit(-1); \ exit(-1); \
} while (0) } while (0)
#define die_errno(msg, ...) die(msg ": %s", ##__VA_ARGS__, strerror(errno)) #define die_errno(msg, ...) die(msg ": %s", ##__VA_ARGS__, strerror(errno))

Loading…
Cancel
Save