Skip to content

Commit c927e6c

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4234a76 commit c927e6c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ extern void verify_non_filename(const char *prefix, const char *name);
234234
*/
235235
#define ALLOC_GROW(x, nr, alloc) \
236236
do { \
237-
if ((nr) >= alloc) { \
237+
if ((nr) > alloc) { \
238238
if (alloc_nr(alloc) < (nr)) \
239239
alloc = (nr); \
240240
else \

0 commit comments

Comments
 (0)