diff --git a/src/osdp_common.h b/src/osdp_common.h index 9a4ce41..38f755b 100644 --- a/src/osdp_common.h +++ b/src/osdp_common.h @@ -81,9 +81,17 @@ static inline __noreturn void die() #define BUG() \ do { \ - printf("BUG at %s:%d %s()", __FILE__, __LINE__, __func__); \ + printf("BUG at %s:%d %s(). Please report this issue!", \ + __FILE__, __LINE__, __func__); \ die(); \ - } while (0); + } while (0) + +#define BUG_ON(pred) \ + do { \ + if (unlikely(pred)) { \ + BUG(); \ + } \ + } while (0) /* Unused type only to estimate ephemeral_data size */ union osdp_ephemeral_data { diff --git a/src/osdp_file.c b/src/osdp_file.c index bdc7556..1e46151 100644 --- a/src/osdp_file.c +++ b/src/osdp_file.c @@ -33,15 +33,11 @@ int osdp_file_cmd_tx_build(struct osdp_pd *pd, uint8_t *buf, int max_len) struct osdp_cmd_file_xfer *p = (struct osdp_cmd_file_xfer *)buf; struct osdp_file *f = TO_FILE(pd); - if (f == NULL) { - LOG_ERR("TX_Build: File ops not registered!"); - return -1; - } - - if (f->state != OSDP_FILE_INPROG) { - LOG_ERR("TX_Build: File transfer is not in progress!"); - return -1; - } + /** + * We should never reach this function if a valid file transfer as in + * progress. + */ + BUG_ON(f == NULL || f->state != OSDP_FILE_INPROG); if ((size_t)max_len <= sizeof(struct osdp_cmd_file_xfer)) { LOG_ERR("TX_Build: insufficient space need:%zu have:%d", diff --git a/utils b/utils index a096d8d..3de34d6 160000 --- a/utils +++ b/utils @@ -1 +1 @@ -Subproject commit a096d8d526be812f628183f3c181393b156c3651 +Subproject commit 3de34d6f2131f6e4ab837fc7d3f2dd20afcd7c1e