Skip to content

Commit

Permalink
libosdp: file: Make impossible conditions as BUG_ON()
Browse files Browse the repository at this point in the history
Signed-off-by: Siddharth Chandrasekaran <[email protected]>
  • Loading branch information
sidcha committed Feb 21, 2024
1 parent 68cb607 commit 627b7da
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
12 changes: 10 additions & 2 deletions src/osdp_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 5 additions & 9 deletions src/osdp_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion utils
Submodule utils updated 1 files
+4 −0 include/utils/utils.h

0 comments on commit 627b7da

Please sign in to comment.