From c565e665781f39cf31c64d85c76224c2fffa9f7d Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 18 Sep 2020 16:39:40 -0400 Subject: util: New BFS_FLEX_SIZEOF() macro for more precise flexible array allocations See http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_282.htm for all the fun behind this. --- bftw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bftw.c') diff --git a/bftw.c b/bftw.c index dc04ce0..0e541c6 100644 --- a/bftw.c +++ b/bftw.c @@ -300,7 +300,7 @@ static size_t bftw_child_nameoff(const struct bftw_file *parent) { /** Create a new bftw_file. */ static struct bftw_file *bftw_file_new(struct bftw_cache *cache, struct bftw_file *parent, const char *name) { size_t namelen = strlen(name); - size_t size = sizeof(struct bftw_file) + namelen + 1; + size_t size = BFS_FLEX_SIZEOF(struct bftw_file, name, namelen + 1); struct bftw_file *file = malloc(size); if (!file) { -- cgit v1.2.3