aboutsummaryrefslogtreecommitdiffstats
path: root/src/msgb.c
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2014-02-28 20:11:21 +0100
committerJacob Erlbeck <jerlbeck@sysmocom.de>2014-03-18 14:10:02 +0100
commit7e86eef4a1d49b6f0e3c18633698ed7a601e9a73 (patch)
tree04f811bb04b35f0202fb8a7f570b55274469e542 /src/msgb.c
parent1512ea6452c123fbf7da325422b4378d64b90087 (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.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/msgb.c b/src/msgb.c
index b2fe1d2c..11068247 100644
--- a/src/msgb.c
+++ b/src/msgb.c
@@ -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