[master] 9cc2fd874 miniobj: Use sizeof for ALLOC_FLEX_OBJ()
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Mon Aug 21 15:26:07 UTC 2023
commit 9cc2fd874758e4cfcbfe2cb22b46fd629041b3ad
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Mon Aug 21 16:40:36 2023 +0200
miniobj: Use sizeof for ALLOC_FLEX_OBJ()
Even though the flexible array may start inside the padding, an array of
zero elements could then lead to less than sizeof bytes.
diff --git a/include/miniobj.h b/include/miniobj.h
index 7551cab53..fcdc9210c 100644
--- a/include/miniobj.h
+++ b/include/miniobj.h
@@ -32,7 +32,7 @@
#define ALLOC_FLEX_OBJ(to, fld, len, type_magic) \
do { \
- (to) = calloc(1, offsetof(typeof(*(to)), fld) + \
+ (to) = calloc(1, sizeof(*(to)) + \
((len) * sizeof *((to)->fld))); \
if ((to) != NULL) \
(to)->magic = (type_magic); \
More information about the varnish-commit
mailing list