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 <armbru@pond.sub.org>
This commit is contained in:
parent
80bf4ec34b
commit
d58bea5458
2 changed files with 8 additions and 1 deletions
|
@ -82,6 +82,13 @@ extern void (*oops_handler)(void);
|
||||||
#define BUILD_ASSERT_ONE(cond) \
|
#define BUILD_ASSERT_ONE(cond) \
|
||||||
(sizeof(char[1 - 2 * !(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));
|
void exit_nomem(void) ATTRIBUTE((noreturn));
|
||||||
|
|
||||||
/* return codes from command routines */
|
/* return codes from command routines */
|
||||||
|
|
|
@ -516,7 +516,7 @@ show_product(int tlev)
|
||||||
pp->p_sname,
|
pp->p_sname,
|
||||||
pp->p_type < 0 ? ' ' : ichr[pp->p_type].i_mnem,
|
pp->p_type < 0 ? ' ' : ichr[pp->p_type].i_mnem,
|
||||||
pp->p_cost);
|
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++) {
|
for (i = 0; i < 3; i++) {
|
||||||
if (i < MAXPRCON && pp->p_camt[i]
|
if (i < MAXPRCON && pp->p_camt[i]
|
||||||
&& pp->p_ctype[i] > I_NONE && pp->p_ctype[i] <= I_MAX)
|
&& pp->p_ctype[i] > I_NONE && pp->p_ctype[i] <= I_MAX)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue