From 5853f084a0212b7f50cbdd18cfbc15f90de240ff Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Sun, 16 Jan 2011 17:38:22 +0100 Subject: 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. --- include/osmocore/msgb.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include') 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 #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); -- cgit v1.2.3