diff options
author | Jacob Erlbeck <jerlbeck@sysmocom.de> | 2014-02-28 20:11:21 +0100 |
---|---|---|
committer | Jacob Erlbeck <jerlbeck@sysmocom.de> | 2014-03-18 14:10:02 +0100 |
commit | 7e86eef4a1d49b6f0e3c18633698ed7a601e9a73 (patch) | |
tree | 04f811bb04b35f0202fb8a7f570b55274469e542 /src/msgb.c | |
parent | 1512ea6452c123fbf7da325422b4378d64b90087 (diff) |
msgb: Optionally declare some msgb struct fields as const
Writing directly to following struct fields may cause inconsistencies
that are hard to debug:
data_len, len, head, tail, data
In general, the available macros and functions should be used to
modify them instead.
This patch declares these fields as const if
MSGB_DISABLE_DIRECT_WRITE is defined. Doing so may lead to warnings
and errors, therefore this macro is only defined for libosmocore yet,
where at least the errors are also fixed by this patch.
The main purpose is to maintain consistency, so only modifing the
fields themselves is restricted. It's still possible to modify the
data the pointers refer to.
Sponsored-by: On-Waves ehf
Diffstat (limited to 'src/msgb.c')
-rw-r--r-- | src/msgb.c | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -55,11 +55,11 @@ struct msgb *msgb_alloc(uint16_t size, const char *name) return NULL; } - msg->data_len = size; - msg->len = 0; - msg->data = msg->_data; - msg->head = msg->_data; - msg->tail = msg->_data; + msg->__data_len = size; + msg->__len = 0; + msg->__data = msg->_data; + msg->__head = msg->_data; + msg->__tail = msg->_data; return msg; } @@ -113,10 +113,10 @@ struct msgb *msgb_dequeue(struct llist_head *queue) */ void msgb_reset(struct msgb *msg) { - msg->len = 0; - msg->data = msg->_data; - msg->head = msg->_data; - msg->tail = msg->_data; + msg->__len = 0; + msg->__data = msg->_data; + msg->__head = msg->_data; + msg->__tail = msg->_data; msg->trx = NULL; msg->lchan = NULL; @@ -133,7 +133,7 @@ void msgb_reset(struct msgb *msg) */ uint8_t *msgb_data(const struct msgb *msg) { - return msg->data; + return msg->__data; } /*! \brief get length of message buffer |