From dcc880a002b317ea8230b001d95f12eccc362f28 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sun, 11 Dec 2016 15:29:13 +0000 Subject: [PATCH] assert: _a_ expression string shouldn't be part of the format string The expression may contain the % operator. --- src/common/assert.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/common/assert.h b/src/common/assert.h index c9d3b2d0..4b209535 100644 --- a/src/common/assert.h +++ b/src/common/assert.h @@ -5,7 +5,6 @@ #pragma once #include -#include // For asserts we'd like to keep all the junk executed when an assert happens away from the // important code in the function. One way of doing this is to put all the relevant code inside a @@ -22,19 +21,19 @@ __declspec(noinline, noreturn) #endif static void assert_noinline_call(const Fn& fn) { fn(); - exit(EXIT_FAILURE); // Keeps GCC's mouth shut about this actually returning + throw ""; } #define ASSERT(_a_) \ do if (!(_a_)) { assert_noinline_call([] { \ - fprintf(stderr, "Assertion Failed!\n" #_a_); \ - throw ""; \ + fprintf(stderr, "Assertion Failed!: %s\n", #_a_); \ }); } while (false) #define ASSERT_MSG(_a_, ...) \ do if (!(_a_)) { assert_noinline_call([&] { \ - fprintf(stderr, "Assertion Failed!\n" #_a_ "\n" __VA_ARGS__); \ - throw ""; \ + fprintf(stderr, "Assertion Failed!: %s\n", #_a_); \ + fprintf(stderr, "Message: " __VA_ARGS__); \ + fprintf(stderr, "\n"); \ }); } while (false) #define UNREACHABLE() ASSERT_MSG(false, "Unreachable code!")