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.
diff --git a/include/osmocore/msgb.h b/include/osmocore/msgb.h
index 6fd24c7..c4f4430 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 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);