From: Jeff King Date: Sat, 16 Jun 2007 22:37:39 +0000 (-0400) Subject: Fix ALLOC_GROW off-by-one X-Git-Tag: v1.5.3-rc0~66^2~1 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c927e6c69b50877e116340671ed35aaf6d3a8f49;p=git.git 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: Jeff King Signed-off-by: Junio C Hamano --- diff --git a/cache.h b/cache.h index 9700ca501..aba7a5ec0 100644 --- a/cache.h +++ b/cache.h @@ -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 \