From 02bb2768f176164099a30b74504c86e1accb7bb1 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Fri, 19 Nov 2021 16:51:52 +0100 Subject: [PATCH 1/2] config: Remove some "UNREACHABLE" UB footguns Every branch of these long if/else if/else chains returns, so the compiler can figure out on its own that the last line is never reached. If, for some reason, one of the branches does not return (as was the case after 205f1f7, fixed by b22322b), this would usually result in a compiler error ("control reaches end of non-void function"), but adding UNREACHABLE transforms this into silent undefined behaviour. --- config.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/config.c b/config.c index 2f12e201..c655813d 100644 --- a/config.c +++ b/config.c @@ -1012,8 +1012,6 @@ parse_section_main(struct context *ctx) LOG_CONTEXTUAL_ERR("not a valid option: %s", key); return false; } - - UNREACHABLE(); } static bool @@ -2340,8 +2338,6 @@ parse_section_tweak(struct context *ctx) LOG_CONTEXTUAL_ERR("not a valid option: %s", key); return false; } - - UNREACHABLE(); } static bool From 877c1e6f07df5110dd08d6c6aa01987ca1b46a24 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sat, 20 Nov 2021 11:58:01 +0100 Subject: [PATCH 2/2] config: Simplify render-timer option handling --- config.c | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/config.c b/config.c index c655813d..f8273484 100644 --- a/config.c +++ b/config.c @@ -2263,29 +2263,10 @@ parse_section_tweak(struct context *ctx) return false; } - switch (mode) { - case 0: - conf->tweak.render_timer_osd = false; - conf->tweak.render_timer_log = false; - return true; - - case 1: - conf->tweak.render_timer_osd = true; - conf->tweak.render_timer_log = false; - return true; - - case 2: - conf->tweak.render_timer_osd = false; - conf->tweak.render_timer_log = true; - return true; - - case 3: - conf->tweak.render_timer_osd = true; - conf->tweak.render_timer_log = true; - return true; - } - - UNREACHABLE(); + xassert(0 <= mode && mode <= 3); + conf->tweak.render_timer_osd = mode == 1 || mode == 3; + conf->tweak.render_timer_log = mode == 2 || mode == 3; + return true; } else if (strcmp(key, "delayed-render-lower") == 0) {