summaryrefslogtreecommitdiff
path: root/pack.h
diff options
context:
space:
mode:
authorLibravatar Jeff King <peff@peff.net>2017-03-16 10:27:20 -0400
committerLibravatar Junio C Hamano <gitster@pobox.com>2017-03-16 11:33:43 -0700
commitf20754802a280c57a1e5886605b6805bbf040c63 (patch)
treed25588005dd09e4f03cc851ee1ab39f8854b8e05 /pack.h
parentreplace snprintf with odb_pack_name() (diff)
downloadtgif-f20754802a280c57a1e5886605b6805bbf040c63.tar.xz
index-pack: make pointer-alias fallbacks safer
The final() function accepts a NULL value for certain parameters, and falls back to writing into a reusable "name" buffer, and then either: 1. For "keep_name", requiring all uses to do "keep_name ? keep_name : name.buf". This is awkward, and it's easy to accidentally look at the maybe-NULL keep_name. 2. For "final_index_name" and "final_pack_name", aliasing those pointers to the "name" buffer. This is easier to use, but the aliased pointers become invalid after the buffer is reused (this isn't a bug now, but it's a potential pitfall). One way to make this safer would be to introduce an extra pointer to do the aliasing, and have its lifetime match the validity of the "name" buffer. But it's still easy to accidentally use the wrong name (i.e., to use "final_pack_name" instead of the aliased pointer). Instead, let's use three separate buffers that will remain valid through the function. That makes it safe to alias the pointers and use them consistently. The extra allocations shouldn't matter, as this function is not performance sensitive. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pack.h')
0 files changed, 0 insertions, 0 deletions