aboutsummaryrefslogtreecommitdiffstats
path: root/include/osmocore
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2011-01-16 17:38:22 +0100
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-01-16 20:29:48 +0100
commit5853f084a0212b7f50cbdd18cfbc15f90de240ff (patch)
tree0df86719874c3161fb9724c0bd2c9843a8225b93 /include/osmocore
parent52c07ca6c5708e4b20d8a6b6f40d09f74fef43ba (diff)
msgb: Make sure at compile time that headroom is smaller than size
All current code is using constants to allocate the msgb with headroom. Use a static_assert to make sure that the headroom is smaller than the size. This makes API misusage unlikely to happen.
Diffstat (limited to 'include/osmocore')
-rw-r--r--include/osmocore/msgb.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/include/osmocore/msgb.h b/include/osmocore/msgb.h
index 6fd24c7f..c4f44305 100644
--- a/include/osmocore/msgb.h
+++ b/include/osmocore/msgb.h
@@ -22,6 +22,7 @@
#include <stdint.h>
#include "linuxlist.h"
+#include "utils.h"
#define MSGB_DEBUG
@@ -180,6 +181,8 @@ static inline void msgb_reserve(struct msgb *msg, int len)
static inline struct msgb *msgb_alloc_headroom(int size, int headroom,
const char *name)
{
+ static_assert(size > headroom, headroom_bigger);
+
struct msgb *msg = msgb_alloc(size, name);
if (msg)
msgb_reserve(msg, headroom);