aboutsummaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-03-16 10:27:20 -0400
committerJunio C Hamano <gitster@pobox.com>2017-03-16 11:33:43 -0700
commitf20754802a280c57a1e5886605b6805bbf040c63 (patch)
treed25588005dd09e4f03cc851ee1ab39f8854b8e05 /sha1_file.c
parentba47a3088f04ac3d2833bea56ee366be1054db8d (diff)
downloadgit-f20754802a280c57a1e5886605b6805bbf040c63.tar.gz
git-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 'sha1_file.c')
0 files changed, 0 insertions, 0 deletions