diff options
author | Vadim Yanitskiy <vyanitskiy@sysmocom.de> | 2023-02-24 18:00:13 +0700 |
---|---|---|
committer | fixeria <vyanitskiy@sysmocom.de> | 2023-02-27 09:58:46 +0000 |
commit | 22ade291ad8f90dc5e4581630bfae21bfd1dcdc3 (patch) | |
tree | 3935c829fb31d6a8706e2ed506920ff82423c303 /include/osmocom/core | |
parent | 65e0edc73fa921632641463f82a7df2fa15ad7d8 (diff) |
msgb: use OSMO_ASSERT in msgb_alloc_headroom[_c]()
This patch is a preparation for the upcoming change making use of
the built-in static_assert(), which is available since C11.
When using built-in static_assert(), gcc v12.2.1 fails:
include/osmocom/core/msgb.h: In function 'msgb_alloc_headroom_c':
include/osmocom/core/msgb.h:532:33: error: expression in static assertion is not constant
532 | osmo_static_assert(size >= headroom, headroom_bigger);
include/osmocom/core/utils.h:86:24: note: in definition of macro 'osmo_static_assert'
86 | static_assert((exp), "(" #exp ") failed")
| ^~~
include/osmocom/core/msgb.h: In function 'msgb_alloc_headroom':
include/osmocom/core/msgb.h:554:33: error: expression in static assertion is not constant
554 | osmo_static_assert(size >= headroom, headroom_bigger);
include/osmocom/core/utils.h:86:24: note: in definition of macro 'osmo_static_assert'
86 | static_assert((exp), "(" #exp ") failed")
| ^~~
These are not really *static* assert()s, because they operate on the
user supplied arguments 'size' and 'headroom', which are not guaranteed
to be integer literals. Neither they trigger compilation failures
as expected, nor do they abort at run-time. They simply do nothing.
Change-Id: I17ef4f3283ce20a5b452b7874c826acfb02a0123
Diffstat (limited to 'include/osmocom/core')
-rw-r--r-- | include/osmocom/core/msgb.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/include/osmocom/core/msgb.h b/include/osmocom/core/msgb.h index 3fdb189d..2529c0e8 100644 --- a/include/osmocom/core/msgb.h +++ b/include/osmocom/core/msgb.h @@ -529,7 +529,7 @@ static inline int msgb_l3trim(struct msgb *msg, int l3len) static inline struct msgb *msgb_alloc_headroom_c(const void *ctx, uint16_t size, uint16_t headroom, const char *name) { - osmo_static_assert(size >= headroom, headroom_bigger); + OSMO_ASSERT(size >= headroom); struct msgb *msg = msgb_alloc_c(ctx, size, name); if (OSMO_LIKELY(msg)) @@ -551,7 +551,7 @@ static inline struct msgb *msgb_alloc_headroom_c(const void *ctx, uint16_t size, static inline struct msgb *msgb_alloc_headroom(uint16_t size, uint16_t headroom, const char *name) { - osmo_static_assert(size >= headroom, headroom_bigger); + OSMO_ASSERT(size >= headroom); struct msgb *msg = msgb_alloc(size, name); if (OSMO_LIKELY(msg)) |