From d58bea54582ab1674782ce76c802894da5cf945d Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 4 Jul 2015 16:19:16 +0200 Subject: [PATCH] Convert run-time to build-time assertion There's just one, in show_product(). Use new BUILD_ASSERT() there, because its contract is even simpler than BUILD_ASSERT_ONE()'s. Signed-off-by: Markus Armbruster --- include/misc.h | 7 +++++++ src/lib/subs/show.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/misc.h b/include/misc.h index 29a3671c..3217c39a 100644 --- a/include/misc.h +++ b/include/misc.h @@ -82,6 +82,13 @@ extern void (*oops_handler)(void); #define BUILD_ASSERT_ONE(cond) \ (sizeof(char[1 - 2 * !(cond)])) +/* + * Assert constant expression @cond. + * If @cond is zero, force a compilation error. + */ +#define BUILD_ASSERT(cond) \ + ((void)BUILD_ASSERT_ONE(cond)) + void exit_nomem(void) ATTRIBUTE((noreturn)); /* return codes from command routines */ diff --git a/src/lib/subs/show.c b/src/lib/subs/show.c index b214af15..0ec50156 100644 --- a/src/lib/subs/show.c +++ b/src/lib/subs/show.c @@ -516,7 +516,7 @@ show_product(int tlev) pp->p_sname, pp->p_type < 0 ? ' ' : ichr[pp->p_type].i_mnem, pp->p_cost); - (void)CANT_HAPPEN(MAXPRCON > 3); /* output has only three columns */ + BUILD_ASSERT(MAXPRCON <= 3); /* output has only three columns */ for (i = 0; i < 3; i++) { if (i < MAXPRCON && pp->p_camt[i] && pp->p_ctype[i] > I_NONE && pp->p_ctype[i] <= I_MAX)