From ca0e886159fa79829ee10585db8749d2f41b446f Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 14 Oct 2023 18:20:22 +0300 Subject: [PATCH] spa: support: allow spa_log_xxx(NULL, ...) again with UBSan Calling the spa_log_xxx macros with NULL log used to be allowed, and it's used in some tests. Write the NULL check in a way the compiler can understand and make UBSan a happy UBSan. --- spa/include/spa/support/log.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spa/include/spa/support/log.h b/spa/include/spa/support/log.h index af7cda8f7..450ff2624 100644 --- a/spa/include/spa/support/log.h +++ b/spa/include/spa/support/log.h @@ -208,12 +208,13 @@ static inline bool spa_log_level_topic_enabled(const struct spa_log *log, { enum spa_log_level max_level; + if (SPA_UNLIKELY(!log)) + return false; + if (topic && topic->has_custom_level) max_level = topic->level; - else if (log) - max_level = log->level; else - max_level = SPA_LOG_LEVEL_NONE; + max_level = log->level; return level <= max_level; } @@ -222,8 +223,8 @@ static inline bool spa_log_level_topic_enabled(const struct spa_log *log, #define spa_log_logt(l,lev,topic,...) \ ({ \ struct spa_log *_l = l; \ - struct spa_interface *_if = &_l->iface; \ if (SPA_UNLIKELY(spa_log_level_topic_enabled(_l, topic, lev))) { \ + struct spa_interface *_if = &_l->iface; \ if (!spa_interface_call(_if, \ struct spa_log_methods, logt, 1, \ lev, topic, \ @@ -238,8 +239,8 @@ static inline bool spa_log_level_topic_enabled(const struct spa_log *log, #define spa_log_logtv(l,lev,topic,...) \ ({ \ struct spa_log *_l = l; \ - struct spa_interface *_if = &_l->iface; \ if (SPA_UNLIKELY(spa_log_level_topic_enabled(_l, topic, lev))) { \ + struct spa_interface *_if = &_l->iface; \ if (!spa_interface_call(_if, \ struct spa_log_methods, logtv, 1, \ lev, topic, \