Unverified Commit 8bc28ccd authored by Dridi Boukelmoune's avatar Dridi Boukelmoune Committed by Nils Goroll

miniobj: Extract SIZEOF_FLEX_OBJ() macro

committer edit: Updated Flexelint silencing

Picked from #4271
parent 4fe462a4
......@@ -283,8 +283,8 @@
-emacro(774, REPLACE)
// Flexelint does not understand offsetof(typeof(*ptr))
-emacro(10, ALLOC_FLEX_OBJ)
-emacro(40, ALLOC_FLEX_OBJ)
-emacro(10, SIZEOF_FLEX_OBJ)
-emacro(40, SIZEOF_FLEX_OBJ)
// It is ok to default after handling a few select SLT_* tags
......
......@@ -37,10 +37,12 @@
(to)->magic = (type_magic); \
} while (0)
#define SIZEOF_FLEX_OBJ(to, fld, len) \
(offsetof(typeof(*to), fld) + sizeof *(to)->fld * len)
#define ALLOC_FLEX_OBJ(to, fld, len, type_magic) \
do { \
(to) = calloc(1, offsetof(typeof(*to), fld) + \
sizeof *(to)->fld * len); \
(to) = calloc(1, SIZEOF_FLEX_OBJ(to, fld, len)); \
if ((to) != NULL) \
(to)->magic = (type_magic); \
} while (0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment