From e82bc0ca23d7a75d4801e5ff48b0b5510771ea1a Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Thu, 21 Feb 2019 14:15:25 +0000 Subject: [PATCH] Silence a warning in release build Signed-off-by: Yuxuan Shui --- src/options.c | 3 +-- src/utils.h | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/options.c b/src/options.c index bfca5f5..3826520 100644 --- a/src/options.c +++ b/src/options.c @@ -820,8 +820,7 @@ void get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable, // Fill default blur kernel if (opt->blur_background && !opt->blur_kerns[0]) { - bool ret = parse_blur_kern_lst("3x3box", opt->blur_kerns, MAX_BLUR_PASS, &conv_kern_hasneg); - assert(ret); + CHECK(parse_blur_kern_lst("3x3box", opt->blur_kerns, MAX_BLUR_PASS, &conv_kern_hasneg)); } if (opt->resize_damage < 0) { diff --git a/src/utils.h b/src/utils.h index d5e3edc..d6f6aa0 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,15 +1,15 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright (c) 2018 Yuxuan Shui #pragma once -#include +#include #include #include #include #include #include +#include #include #include -#include #include "compiler.h" @@ -32,10 +32,19 @@ safe_isnan(double a) { /// Same as assert false, but make sure we abort _even in release builds_. /// Silence compiler warning caused by release builds making some code paths reachable. -attr_noret static inline void BUG(void) { - assert(false); - abort(); -} +#define BUG() \ + do { \ + assert(false); \ + abort(); \ + } while (0) + +/// Same as assert, but evaluates the expression even in release builds +#define CHECK(expr) \ + do { \ + __auto_type __tmp = (expr); \ + assert(__tmp); \ + (void)__tmp; \ + } while (0) /** * Normalize an int value to a specific range. @@ -111,8 +120,8 @@ static inline double attr_const normalize_d(double d) { return normalize_d_range(d, 0.0, 1.0); } -attr_noret void report_allocation_failure(const char *func, const char *file, - unsigned int line); +attr_noret void +report_allocation_failure(const char *func, const char *file, unsigned int line); /** * @brief Quit if the passed-in pointer is empty.