提交 c927e6c6 编写于 作者: J Jeff King 提交者: Junio C Hamano

Fix ALLOC_GROW off-by-one

The ALLOC_GROW macro will never let us fill the array completely,
instead allocating an extra chunk if that would be the case. This is
because the 'nr' argument was originally treated as "how much we do have
now" instead of "how much do we want". The latter makes much more
sense because you can grow by more than one item.

This off-by-one never resulted in an error because it meant we were
overly conservative about when to allocate. Any callers which passed
"how much we have now" need to be updated, or they will fail to allocate
enough.
Signed-off-by: NJeff King <peff@peff.net>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 4234a761
......@@ -234,7 +234,7 @@ extern void verify_non_filename(const char *prefix, const char *name);
*/
#define ALLOC_GROW(x, nr, alloc) \
do { \
if ((nr) >= alloc) { \
if ((nr) > alloc) { \
if (alloc_nr(alloc) < (nr)) \
alloc = (nr); \
else \
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册