diff options
author | arehbein <arehbein@sysmocom.de> | 2023-07-08 00:33:20 +0200 |
---|---|---|
committer | arehbein <arehbein@sysmocom.de> | 2023-07-09 03:38:49 +0200 |
commit | 9b7adb07da1ec1f6e21dae2c3271d8536ae33d15 (patch) | |
tree | 4645223c19e58c52fa9bfe76ba55bb1ed1a8989f | |
parent | 5aeeb27ee32289514f9704468b4da30e9d8f43e1 (diff) |
msgb: Add helper macro to decide if a segment is incompletearehbein/libosmocore_segm_cb_changes
This helps avoid common logical fallacies that that happen
quickly during coding (i.e. giving a false logical condition)
for a condition any segmentation callback will need.
Related: OS#5753
Change-Id: Ifc7cf0629e93864bfb3e36c64143d4ccc777e4b6
-rw-r--r-- | include/osmocom/core/msgb.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/include/osmocom/core/msgb.h b/include/osmocom/core/msgb.h index 5c58c845..372b85b0 100644 --- a/include/osmocom/core/msgb.h +++ b/include/osmocom/core/msgb.h @@ -773,4 +773,11 @@ static inline const char *msgb_hexdump_l4(const struct msgb *msg) return osmo_hexdump((const unsigned char*) msgb_l4(msg), msgb_l4len(msg)); } +/*! Macro for checking a simple condition (to avoid accidental bugs) + * \param[in] msg Target 'struct msg *' + * \param[in] len_from_msg_metadata Length of data as expected from metadata of msg + * \returns boolean indicating if the data segment starting at msg->data is incomplete + */ +#define msgb_segment_is_incomplete(len_from_msg_metadata, msg)\ + (len_from_msg_metadata > (msg)->len) /*! @} */ |