From 7235d906ff289577507d3569a8362990bcc13372 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 21 Sep 2023 11:42:43 -0400 Subject: [PATCH] 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 --- lib/loglib.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/loglib.h b/lib/loglib.h index 64d99fadb..4fa8ece68 100644 --- a/lib/loglib.h +++ b/lib/loglib.h @@ -104,8 +104,10 @@ INLINE int __get_log_level(unsigned int idx) { #define die(fmt, ...) do { \ - fprintf(stderr, "Fatal error: " fmt "\n", ##__VA_ARGS__); \ - ilog(LOG_CRIT, "Fatal error: " fmt, ##__VA_ARGS__); \ + char *__msg = g_strdup_printf(fmt, ##__VA_ARGS__); \ + fprintf(stderr, "Fatal error: %s\n", __msg); \ + ilog(LOG_CRIT, "Fatal error: %s", __msg); \ + g_free(__msg); \ exit(-1); \ } while (0) #define die_errno(msg, ...) die(msg ": %s", ##__VA_ARGS__, strerror(errno))