@@ -107,24 +107,31 @@ union osdp_ephemeral_data {
107107 * input_check(ctx);
108108 * input_check(ctx, pd);
109109 */
110- #define input_check_init (ctx ) \
111- assert(ctx); \
112- TO_OSDP(ctx)->_magic = OSDP_CTX_MAGIC;
113- #define input_check_osdp_ctx (ctx ) \
114- assert(ctx); \
115- assert(TO_OSDP(ctx)->_magic == OSDP_CTX_MAGIC);
116- #define input_check_pd_offset (ctx , pd ) \
117- if (pd < 0 || pd >= NUM_PD(ctx)) { \
118- LOG_PRINT("Invalid PD number %d", pd); \
119- return -1; \
120- }
121- #define input_check2 (_1 , _2 ) \
122- input_check_osdp_ctx(_1); \
110+ #define input_check_init (_ctx ) do { \
111+ struct osdp *__ctx = (struct osdp *)_ctx; \
112+ assert(__ctx); \
113+ __ctx->_magic = OSDP_CTX_MAGIC; \
114+ } while (0)
115+ #define input_check_osdp_ctx (_ctx ) do { \
116+ struct osdp *__ctx = (struct osdp *)_ctx; \
117+ BUG_ON(__ctx == NULL); \
118+ BUG_ON(__ctx->_magic != OSDP_CTX_MAGIC); \
119+ } while (0)
120+ #define input_check_pd_offset (_ctx , _pd ) do { \
121+ struct osdp *__ctx = (struct osdp *)_ctx; \
122+ int __pd = _pd; \
123+ if (__pd < 0 || __pd >= __ctx->_num_pd) { \
124+ LOG_PRINT("Invalid PD number %d", __pd); \
125+ return -1; \
126+ } \
127+ } while (0)
128+ #define input_check2 (_1 , _2 ) \
129+ input_check_osdp_ctx(_1); \
123130 input_check_pd_offset(_1, _2);
124- #define input_check1 (_1 ) \
131+ #define input_check1 (_1 ) \
125132 input_check_osdp_ctx(_1);
126133#define get_macro (_1 , _2 , macro , ...) macro
127- #define input_check (...) \
134+ #define input_check (...) \
128135 get_macro(__VA_ARGS__, input_check2, input_check1)(__VA_ARGS__)
129136
130137/**
0 commit comments