Re: [PATCH 04/18] add helpers for allocating flex-array structs
From: Eric Sunshine <hidden>
Date: 2016-06-15 23:08:15
On Mon, Feb 15, 2016 at 4:50 PM, Jeff King [off-list ref] wrote:
Allocating a struct with a flex array is pretty simple in practice: you over-allocate the struct, then copy some data into the over-allocation. But it can be a slight pain to make sure you're allocating and copying the right amounts. This patch adds a few helpers to turn simple cases of into a
Grammo: "cases of into"
quoted hunk ↗ jump to hunk
one-liner that properly checks for overflow. See the embedded documentation for details. [...] Signed-off-by: Jeff King <redacted> ---diff --git a/git-compat-util.h b/git-compat-util.h@@ -782,6 +782,68 @@ extern FILE *fopen_for_writing(const char *path); + * struct foo *f; + * FLEX_ALLOC_STR(f, name, src); + * + * and "name" will point to a block of memory after the struct, which will be + * freed along with the struct (but the pointer can be repoined anywhere).
"repoined"?
+ * The *_STR variants accept a string parameter rather than a ptr/len + * combination.