From 98cfbc7c3c6a533f3202cdee10019774daaa0b07 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Sun, 19 Feb 2017 17:37:32 +0300 Subject: [PATCH] Properly wrap `kak_assert` into a do-while scope Expanding the `kak_assert` macro to either an `if` statement or nothing leads to issues when the macro is used in a conditional statement that doesn't use braces. Example: ncurses_ui.cc:476, in non debug mode, the macro will expand to an empty line, resulting in the `ungetch` call not being executed if the `ioctl` call succeeds (line 448). --- src/assert.hh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/assert.hh b/src/assert.hh index 4d6c3782..406420d8 100644 --- a/src/assert.hh +++ b/src/assert.hh @@ -17,12 +17,13 @@ void on_assert_failed(const char* message); #define TOSTRING(X) STRINGIFY(X) #ifdef KAK_DEBUG - #define kak_assert(...) \ + #define kak_assert(...) do { \ if (not (__VA_ARGS__)) \ on_assert_failed("assert failed \"" #__VA_ARGS__ \ - "\" at " __FILE__ ":" TOSTRING(__LINE__)) + "\" at " __FILE__ ":" TOSTRING(__LINE__)); \ + } while (0) #else - #define kak_assert(...) + #define kak_assert(...) do {} while (0) #endif