prevents ub in u3x_cap and u3x_mas

This commit is contained in:
Joe Bryan 2018-12-08 19:48:08 -05:00
parent 76fbb1d918
commit bdc7179a28

View File

@ -38,12 +38,15 @@
/* u3x_cap(): root axis, 2 or 3.
*/
# define u3x_cap(a_w) (0x2 | (a_w >> (u3x_dep(a_w) - 1)))
# define u3x_cap(a_w) ({ \
c3_assert( 1 < a_w ); \
(0x2 | (a_w >> (u3x_dep(a_w) - 1))); })
/* u3x_mas(): remainder after cap.
*/
# define u3x_mas(a_w) \
( (a_w & ~(1 << u3x_dep(a_w))) | (1 << (u3x_dep(a_w) - 1)) )
# define u3x_mas(a_w) ({ \
c3_assert( 1 < a_w ); \
( (a_w & ~(1 << u3x_dep(a_w))) | (1 << (u3x_dep(a_w) - 1)) ); })
/* u3x_peg(): connect two axes.
*/