[master] 8bc28ccd3 miniobj: Extract SIZEOF_FLEX_OBJ() macro
Nils Goroll
nils.goroll at uplex.de
Thu Feb 13 09:37:07 UTC 2025
commit 8bc28ccd3417092a1197845e5450214a126a82e4
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Thu Feb 13 08:49:22 2025 +0100
miniobj: Extract SIZEOF_FLEX_OBJ() macro
committer edit: Updated Flexelint silencing
Picked from #4271
diff --git a/flint.lnt b/flint.lnt
index f8340ea20..4cc5cb348 100644
--- a/flint.lnt
+++ b/flint.lnt
@@ -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
diff --git a/include/miniobj.h b/include/miniobj.h
index ecb341f49..df5018d96 100644
--- a/include/miniobj.h
+++ b/include/miniobj.h
@@ -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)
More information about the varnish-commit
mailing list