summaryrefslogtreecommitdiff
path: root/argv-array.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-02-22 17:43:25 -0500
committerJunio C Hamano <gitster@pobox.com>2016-02-22 14:50:32 -0800
commit3689539127f786f32ff04da374d37cc1f72fb918 (patch)
treeb3e860b9335b096490a581e6b2fdeb3ac9e6e741 /argv-array.c
parente7792a74bcf7fcd554b4546fc91122b8c2af7d75 (diff)
downloadgit-3689539127f786f32ff04da374d37cc1f72fb918.tar.gz
add helpers for allocating flex-array structs
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 flex-array struct allocation into a one-liner that properly checks for overflow. See the embedded documentation for details. Ideally we could provide a more flexible version that could handle multiple strings, like: FLEX_ALLOC_FMT(ref, name, "%s%s", prefix, name); But we have to implement this as a macro (because of the offset calculation of the flex member), which means we would need all compilers to support variadic macros. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'argv-array.c')
0 files changed, 0 insertions, 0 deletions