summaryrefslogtreecommitdiff
path: root/unpack-trees.h
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2020-01-30 09:53:38 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-01-30 21:55:30 (GMT)
commit8dd40c0472a8f51f4fba4b8fd28dc3e9421cd7d7 (patch)
treea1b1355b6075426f066cfca9c4ad0a4843c9398a /unpack-trees.h
parent667b76ec5819b151355e322ad9c6264b9cb3f9cd (diff)
downloadgit-8dd40c0472a8f51f4fba4b8fd28dc3e9421cd7d7.zip
git-8dd40c0472a8f51f4fba4b8fd28dc3e9421cd7d7.tar.gz
git-8dd40c0472a8f51f4fba4b8fd28dc3e9421cd7d7.tar.bz2
traverse_trees(): use stack array for name entries
We heap-allocate our arrays of name_entry structs, etc, with one entry per tree we're asked to traverse. The code does a raw multiplication in the xmalloc() call, which I find when auditing for integer overflows during allocation. We could "fix" this by using ALLOC_ARRAY() instead. But as it turns out, the maximum size of these arrays is limited at compile time: - merge_trees() always passes in 3 trees - unpack_trees() and its brethren never pass in more than MAX_UNPACK_TREES So we can simplify even further by just using a stack array and bounding it with MAX_UNPACK_TREES. There should be no concern with overflowing the stack, since MAX_UNPACK_TREES is only 8 and the structs themselves are small. Note that since we're replacing xcalloc(), we have to move one of the NULL initializations into a loop. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'unpack-trees.h')
0 files changed, 0 insertions, 0 deletions