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. --- dstring.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dstring.c') diff --git a/dstring.c b/dstring.c index d370598..bfcf9bd 100644 --- a/dstring.c +++ b/dstring.c @@ -37,7 +37,7 @@ static struct dstring *dstrheader(const char *dstr) { /** Get the correct size for a dstring with the given capacity. */ static size_t dstrsize(size_t capacity) { - return sizeof(struct dstring) + capacity + 1; + return BFS_FLEX_SIZEOF(struct dstring, data, capacity + 1); } /** Allocate a dstring with the given contents. */ -- cgit v1.2.3